Active waiting?

Alvaro Gamez alvaro.gamez at
Mon Mar 23 16:20:19 GMT 2015

Hi, Sebastian

2015-03-23 17:00 GMT+01:00 Sebastian Spaeth <Sebastian at>:

> We use a Queue in which all exiting threads are put() and loop around,
> waiting with .get(60) for one of those threads to finish.
> Queue().get(60) will wakeup every 50ms or so to see if the condition has
> been fulfilled. If you do not specify a timeout, there will be no
> wakeups, but the main thread will also not listen (and react) to
> signals, such as sent by CTRL-C (or SIGTERM). So we would run danger of
> hanging indefinitely and not be able to react on Ctrl-C.

Even though that's true, I've found that's not the one who is actively
I've applied attached patch and even though it's true that CTRL-C stops
working, there's still code being executed, thouh I haven't
found yet why.

I don't understand why is this, because latest call to is done with a timeout=None, but still gets
busy on the following pasted lines of trace:

 --- modulename: threading, funcname: wait         print "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ", timeout
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  None         if not self._is_owned():
 --- modulename: threading, funcname: _is_owned         if self.__lock.acquire(0):             return True         waiter = _allocate_lock()         waiter.acquire()         self.__waiters.append(waiter)         saved_state = self._release_save()
 --- modulename: threading, funcname: _release_save         self.__lock.release()           # No state to
save         try:    # restore state no matter what (e.g.,
KeyboardInterrupt)             if timeout is None:                 waiter.acquire()                 while True:                     gotit = waiter.acquire(0)                     if gotit:                     remaining = endtime - _time()                     if remaining <= 0:                     delay = min(delay * 2, remaining,
.05)                     _sleep(delay)

I placed a chunk of XXX to help me search on the trace and timeout is None.
However, after line 244 it jumps to line 255, which is something I cannot

This test has been done with the following patch, which should have solved
the busy waiting thing but doesn't, although breaks ctrl-c as predicted.

diff --git a/offlineimap/ b/offlineimap/
index f69f8a6..1d1fb84 100644
--- a/offlineimap/
+++ b/offlineimap/
@@ -109,7 +109,7 @@ def exitnotifymonitorloop(callback):
             # we need a timeout in the get() call, so that ctrl-c can throw
             # a SIGINT ( A timeout with
             # Queue will raise `Empty`.
-            thrd = exitthreads.get(True, 60)
+            thrd = exitthreads.get(True)
             # request to abort when callback returns true
             do_loop = (callback(thrd) != True)
         except Empty:

Álvaro Gámez Machado
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the OfflineIMAP-project mailing list