Yet another Python threading workaround.
module threading should be taken out back and shot. Condition.wait() is a busywait loop that has negative implications for battery consumption on laptops. Queue.get() in blocking mode blocks SIGINT from being delivered. Argh, argh, argh. Closes: #493801.
This commit is contained in:
parent
b267fd25a6
commit
fe57342448
@ -18,8 +18,8 @@
|
|||||||
|
|
||||||
from threading import *
|
from threading import *
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
from Queue import Queue
|
from Queue import Queue, Empty
|
||||||
import sys, traceback, thread
|
import sys, traceback, thread, time
|
||||||
from offlineimap.ui import UIBase # for getglobalui()
|
from offlineimap.ui import UIBase # for getglobalui()
|
||||||
|
|
||||||
profiledir = None
|
profiledir = None
|
||||||
@ -89,7 +89,7 @@ class threadlist:
|
|||||||
# Exit-notify threads
|
# Exit-notify threads
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
exitthreads = Queue(5)
|
exitthreads = Queue(100)
|
||||||
inited = 0
|
inited = 0
|
||||||
|
|
||||||
def initexitnotify():
|
def initexitnotify():
|
||||||
@ -112,8 +112,14 @@ def exitnotifymonitorloop(callback):
|
|||||||
"""
|
"""
|
||||||
global exitthreads
|
global exitthreads
|
||||||
while 1: # Loop forever.
|
while 1: # Loop forever.
|
||||||
callback(exitthreads.get(True))
|
try:
|
||||||
|
thrd = exitthreads.get(False)
|
||||||
|
print "exitnotifymonitorloop: Got thread\n"
|
||||||
|
callback(thrd)
|
||||||
|
print "exitnotifymonitorloop: callback done\n"
|
||||||
exitthreads.task_done()
|
exitthreads.task_done()
|
||||||
|
except Empty:
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
def threadexited(thread):
|
def threadexited(thread):
|
||||||
"""Called when a thread exits."""
|
"""Called when a thread exits."""
|
||||||
|
Loading…
Reference in New Issue
Block a user