Active waiting?
Nicolas Sebrecht
nicolas.s-dev at laposte.net
Mon Mar 23 17:05:28 GMT 2015
On Mon, Mar 23, 2015 at 05:00:41PM +0100, Sebastian Spaeth wrote:
> Am 23.03.2015 um 15:53 schrieb Nicolas Sebrecht:
> > On Mon, Mar 23, 2015 at 01:01:12PM +0100, Alvaro Gamez wrote:
> >> What a pity :(
> >> If there's anything I can research on this to improve offlineimap
> >> please let me know in which direction.
> >
> > This is a known issue but nobody looked into this deeply.
> >
> > https://github.com/OfflineIMAP/offlineimap/issues/81
> >
> > We need to know which Python code is to blame, whether it's in a library
> > or in our code. With more information we will clearly see if we can do
> > something or not.
>
> Actually, yes, I did look into this previously :-). I added a comment to
> issue 81 to provide a tad more detail. My research is from a few years
> back and I am writing from memory.
Sorry, I can't recall about this. Thanks for the input.
> Thing is, that our main thread needs to wait for it's daughter threads
> to exit. This is in threadutils.py:exitnotifymonitorloop.
>
> 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.
>
> So if you find a solution that lets us wait for daughter threads and
> reacts to Ctrl-C (and other signals), we are gold. Unfortunately, I
> failed to find such a solution. (by, this is related to
> http://bugs.python.org/issue1360).
>
> The good news is that the signal issue seems to have been solved in
> python3 (according to the upstream bug report), so we are using python3,
> we should be able to use that code without any timeout, and save lots of
> wakeups. (untested).
Good to know.
Can't we do something like that?
--- >8 ---
Subject: [PATCH] WIP: avoid Queue.get() too much to avoid battery sucking
From: Nicolas Sebrecht <nicolas.s-dev at laposte.net>
TODO: add new configuration option.
---
offlineimap/threadutil.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/offlineimap/threadutil.py b/offlineimap/threadutil.py
index f69f8a6..edc57fb 100644
--- a/offlineimap/threadutil.py
+++ b/offlineimap/threadutil.py
@@ -23,6 +23,8 @@ except ImportError: # python3
import traceback
import os.path
import sys
+import time
+
from offlineimap.ui import getglobalui
######################################################################
@@ -112,6 +114,7 @@ def exitnotifymonitorloop(callback):
thrd = exitthreads.get(True, 60)
# request to abort when callback returns true
do_loop = (callback(thrd) != True)
+ time.sleep(2)
except Empty:
pass
--
Nicolas Sebrecht
More information about the OfflineIMAP-project
mailing list