[PATCH] Simplify exit thread evaluation

Leif Walsh leif.walsh at gmail.com
Wed Dec 1 19:02:01 GMT 2010


Just tested this and it blocks SIGINT from killing offlineimap.  I don't
remember if you need to set a signal handler or change how you use the
queue.  Another solution may be to put this polling logic in another
daemon thread and let the main thread exit without waiting for it.  This
is without much knowledge of the program's architecture, I'll have better
suggestions after I've poked around a bit longer.

On Wed, 1 Dec 2010, Sebastian Spaeth wrote:

> Rather than sleeping for 1 second and poll our exitthread Queue in a
> non-bloking fashion simply call it in a blocking fashion. Works for
> me, and is potentially somewhat faster as we don't do unnecessary
> sleeps after a thread exited.
> 
> Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
> ---
>  offlineimap/threadutil.py |   10 ++++------
>  1 files changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/offlineimap/threadutil.py b/offlineimap/threadutil.py
> index b516f68..579ef35 100644
> --- a/offlineimap/threadutil.py
> +++ b/offlineimap/threadutil.py
> @@ -111,12 +111,10 @@ def exitnotifymonitorloop(callback):
>      the monitor will hold the lock all the while the other thread is waiting.
>      """
>      global exitthreads
> -    while 1:                            # Loop forever.
> -        try:
> -            thrd = exitthreads.get(False)
> -            callback(thrd)
> -        except Empty:
> -            time.sleep(1)
> +    while 1:                            
> +        # Loop forever and call 'callback' for each thread that exited
> +        thrd = exitthreads.get(True)
> +        callback(thrd)
>  
>  def threadexited(thread):
>      """Called when a thread exits."""
> 

-- 
Cheers,
Leif




More information about the OfflineIMAP-project mailing list