Rework keepalive to use time.sleep() instead of event.wait()
This should improve power-management abilities some more The catch is that we can't wait any longer for the kathread to terminate. We were waiting for this in some cases. This is probably not a big deal. fixes deb#434074 fixes #66
This commit is contained in:
parent
b9f73621a5
commit
2a852a8f48
@ -83,15 +83,9 @@ class Account(CustomConfig.ConfigHelperMixin):
|
|||||||
|
|
||||||
refreshperiod = int(self.refreshperiod * 60)
|
refreshperiod = int(self.refreshperiod * 60)
|
||||||
sleepresult = self.ui.sleep(refreshperiod)
|
sleepresult = self.ui.sleep(refreshperiod)
|
||||||
if sleepresult == 2:
|
# Cancel keepalive
|
||||||
# Cancel keep-alive, but don't bother terminating threads
|
|
||||||
for item in kaobjs:
|
for item in kaobjs:
|
||||||
item.stopkeepalive(abrupt = 1)
|
item.stopkeepalive()
|
||||||
return sleepresult
|
|
||||||
else:
|
|
||||||
# Cancel keep-alive and wait for thread to terminate.
|
|
||||||
for item in kaobjs:
|
|
||||||
item.stopkeepalive(abrupt = 0)
|
|
||||||
return sleepresult
|
return sleepresult
|
||||||
|
|
||||||
class AccountSynchronizationMixin:
|
class AccountSynchronizationMixin:
|
||||||
|
@ -20,7 +20,7 @@ import imaplib
|
|||||||
from offlineimap import imaplibutil, imaputil, threadutil
|
from offlineimap import imaplibutil, imaputil, threadutil
|
||||||
from offlineimap.ui import UIBase
|
from offlineimap.ui import UIBase
|
||||||
from threading import *
|
from threading import *
|
||||||
import thread, hmac, os
|
import thread, hmac, os, time
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -309,7 +309,7 @@ class IMAPServer:
|
|||||||
ui.debug('imap', 'keepalive thread started')
|
ui.debug('imap', 'keepalive thread started')
|
||||||
while 1:
|
while 1:
|
||||||
ui.debug('imap', 'keepalive: top of loop')
|
ui.debug('imap', 'keepalive: top of loop')
|
||||||
event.wait(timeout)
|
time.sleep(timeout)
|
||||||
ui.debug('imap', 'keepalive: after wait')
|
ui.debug('imap', 'keepalive: after wait')
|
||||||
if event.isSet():
|
if event.isSet():
|
||||||
ui.debug('imap', 'keepalive: event is set; exiting')
|
ui.debug('imap', 'keepalive: event is set; exiting')
|
||||||
|
@ -171,8 +171,8 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
|
|||||||
"""The default implementation will do nothing."""
|
"""The default implementation will do nothing."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def stopkeepalive(self, abrupt = 0):
|
def stopkeepalive(self):
|
||||||
"""Stop keep alive. If abrupt is 1, stop it but don't bother waiting
|
"""Stop keep alive, but don't bother waiting
|
||||||
for the threads to terminate."""
|
for the threads to terminate."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -57,14 +57,12 @@ class IMAPRepository(BaseRepository):
|
|||||||
self.kathread.setDaemon(1)
|
self.kathread.setDaemon(1)
|
||||||
self.kathread.start()
|
self.kathread.start()
|
||||||
|
|
||||||
def stopkeepalive(self, abrupt = 0):
|
def stopkeepalive(self):
|
||||||
if not hasattr(self, 'kaevent'):
|
if not hasattr(self, 'kaevent'):
|
||||||
# Keepalive is not active.
|
# Keepalive is not active.
|
||||||
return
|
return
|
||||||
|
|
||||||
self.kaevent.set()
|
self.kaevent.set()
|
||||||
if not abrupt:
|
|
||||||
self.kathread.join()
|
|
||||||
del self.kathread
|
del self.kathread
|
||||||
del self.kaevent
|
del self.kaevent
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user