ZyX_I avatar ZyX_I committed 3648971

@%aurum: Fixed process pausing.
python/aurum/repeatedcmd: Added summary() function (useful for debugging)
Made pausing really terminate processes

Comments (0)

Files changed (3)

autoload/aurum.vim

                 \'has_key(v:val, a:key) ? s:F.aget(v:val[a:key], 1) : 0')
 endfunction
 "▶1 aswitch
-let s:pexpr='map(values(v:val), '.
-            \   '"v:val.repo.functions.%s(v:val.repo, v:val.rcid)")'
 function s:F.aswitch()
     let bl=tabpagebuflist()
-    call map(copy(s:abuffers), 'index(bl, +v:key)==-1 ? '.
-                \                   printf(s:pexpr, 'apause').' : '.
-                \                   printf(s:pexpr, 'aresume'))
+    call map(filter(bl, 'has_key(s:abuffers, v:val)'), '"".v:val')
+    call map(filter(values(s:akeys), 'empty(filter(keys(v:val.buffers), '.
+                \                          '"index(bl, v:val)!=-1"))'),
+                \'v:val.repo.functions.apause(v:val.repo, v:val.rcid)')
 endfunction
 augroup AuRCSwitchBuffers
     autocmd BufEnter * :call s:F.aswitch()
     output. All currently existing implementations require python-2* with 
     working threading module.
   aget :: rcid[, now] -> ?                                     *aurum-rf-aget*
-    Output current value of repeatedly run function. With “now” it is not 
-    using cache.
+    Output current value of repeatedly run function. With {now} set to true it 
+    is not using cache. Without {now} or with it set to false it should also 
+    resume what was paused by |aurum-rf-apause|.
   aremove :: rcid                                           *aurum-rf-aremove*
     Stop repeating functions.
   apause :: rcid                                             *aurum-rf-apause*

python/aurum/repeatedcmd.py

         self.func        = func
         self.args        = args
         self.kwargs      = kwargs
-        self.paused      = Value('b', 0)
+        self.value       = None
+        self.process     = None
 
-        def procfunc(queue, qlock, vlock, interval, func, args, kwargs):
-            # Override default signal vim handler with system default behavior 
-            # (i.e. just terminate). Without this hack process.terminate() may 
-            # leave the process alive. Bad, I do not know why it leaves it alive 
-            # only in some limited set of cases.
-            signal(SIGTERM, SIG_DFL)
-            while interval.value > 0:
-                starttime = time.clock()
-                if not self.paused.value:
-                    vlock.acquire()
-                    value     = func(*args, **kwargs)
-                    vlock.release()
-                    qlock.acquire()
-                    # If I only knew the size of func() output I would have used 
-                    # Value()
-                    while(not queue.empty()):
-                        queue.get()
-                    queue.put(value)
-                    qlock.release()
-                try:
-                    time.sleep(interval.value-(time.clock()-starttime))
-                except Exception:
-                    # Work when interval-elapsed results in negative value.
-                    pass
-
-        self.process  = Process(target=procfunc,
-                                args=(self.queue, self.qlock, self.vlock,
-                                      self.interval,
-                                      func, args, kwargs))
-        self.process.start()
-        self.value = None
+        self.start()
 
     def setinterval(self, interval):
         if not self.alive():
 
     def getvalue(self):
         if not self.alive():
-            raise ProcessHaltedError(notalive)
+            result = self.getcurrentvalue()
+            self.start()
+            return result
+
         self.qlock.acquire()
         if self.value is None or not self.queue.empty():
             while(not self.queue.empty()):
         return self.value
 
     def alive(self):
-        return self.process.is_alive() and self.interval.value > 0
+        return (    self.process is not None
+                and self.process.is_alive()
+                and self.interval.value > 0.0)
+
+    def join(self):
+        if (    self.process is not None
+            and self.process.is_alive()
+            and self.interval.value <= 0.0):
+            self.process.join()
+
+    def run(self):
+        # Override default signal vim handler with system default behavior (i.e. 
+        # just terminate). Without this hack process.terminate() may leave the 
+        # process alive. Bad, I do not know why it leaves it alive only in some 
+        # limited set of cases.
+        signal(SIGTERM, SIG_DFL)
+        while self.interval.value > 0.0:
+            starttime = time.clock()
+            self.vlock.acquire()
+            value     = self.func(*self.args, **self.kwargs)
+            self.vlock.release()
+            self.qlock.acquire()
+            # If I only knew the size of func() output I would have used 
+            # Value()
+            while(not self.queue.empty()):
+                self.queue.get()
+            self.queue.put(value)
+            self.qlock.release()
+            try:
+                time.sleep(self.interval.value-(time.clock()-starttime))
+            except Exception:
+                # Work when interval-elapsed results in negative value.
+                pass
+
+    def start(self):
+        if self.alive():
+            return
+        self.join()
+        self.process = Process(target=self.run)
+        self.process.start()
 
     def stop(self):
         if not self.alive():
-            raise ProcessHaltedError(notalive)
+            return
         # For some reason process.terminate() sometimes may not seem to work. 
         # This is a workaround. Seems it is no longer needed with 
         # self.process.join(), just keeping it here for multiprocessing.
         # For threading this is the only way to terminate thread (use old 
         # implementation based on sequence of timers?)
         self.interval.value = -1.0
-        self.paused.value = 1
         try:
             self.process.terminate()
             # Anti-zombie code
             # Threads do not have .terminate method
             pass
 
-    def pause(self):
-        if not self.alive():
-            raise ProcessHaltedError(notalive)
-        if not self.paused.value:
-            self.paused.value   = 1
-            self.interval.value = 1.0
-
-    def resume(self):
-        if not self.alive():
-            raise ProcessHaltedError(notalive)
-        if self.paused.value:
-            self.paused.value   = 0
-            self.interval.value = self.curinterval
-
-    def __del__(self):
-        if self.alive():
-            return self.stop()
+    pause   = stop
+    resume  = start
+    __del__ = stop
 
 processes={}
 
 def resume(rcid):
     global processes
     processes[rcid].resume()
+
+def summary():
+    global processes
+    for rcid in processes:
+        process=processes[rcid]
+        print ('%*s: %s %u %s' %
+               (len(processes), rcid, '+' if process.alive() else '-',
+                process.process.pid, repr(process.args)))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.