Active waiting?

Nicolas Sebrecht nicolas.s-dev at laposte.net
Mon Mar 23 20:49:58 GMT 2015


[ Note: the code lines are badly encoded and look crappy which make them
  hard to read. ]

On Mon, Mar 23, 2015 at 06:27:00PM +0100, Alvaro Gamez wrote:

>    On my previous email I've found keepalive timer to be the worst
>    offender.
>    It's not that bad that when sleeping for a couple seconds too many
>    wakeups arise, but being actively waiting during the whole 29 minutes
>    between restablishing the IDLE connection is pretty much killing my
>    battery life.

Ok.

>    I've never done any python threading programming and don't know much
>    about offlineimap threading architecture, so I don't know if this is
>    possible, but could this simple patch solve the issue?
>    diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
>    index f0b2248..21c3c5c 100644
>    --- a/offlineimap/imapserver.py
>    +++ b/offlineimap/imapserver.py
>    @@ -596,7 +596,7 @@ class IMAPServer:
>    Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  threads.append(idler)
>    Â
>    Â Â Â Â Â Â Â Â Â Â Â Â  self.ui.debug('imap', 'keepalive: waiting for
>    timeout')
>    -Â Â Â Â Â Â Â Â Â Â Â  event.wait(timeout)
>    +Â Â Â Â Â Â Â Â Â Â Â  time.sleep(timeout)
>    Â Â Â Â Â Â Â Â Â Â Â Â  self.ui.debug('imap', 'keepalive: after wait')
>    Â
>    Â Â Â Â Â Â Â Â Â Â Â Â  for idler in threads:

This is wrong because you _force_ waiting until the end of the timeout.
even.wait(timeout) will continue as soon as the event is "set".

Now, due to how we use this Event, it might be acceptable for you.

To get quicker react on events, you could try something like that:

  nloop = timeout / 30
  while nloop > 0:
      if event.isSet():
          break
      time.sleep(30)
      nloop -= 1

which enables to react each 30 seconds at most for events.

-- 
Nicolas Sebrecht




More information about the OfflineIMAP-project mailing list