Removes code and should avoid weird Python situation that causes cpu
wakeups
fixes deb#434074
fixes #66
from threading import *
from StringIO import StringIO
from threading import *
from StringIO import StringIO
import sys, traceback, thread
from offlineimap.ui import UIBase # for getglobalui()
import sys, traceback, thread
from offlineimap.ui import UIBase # for getglobalui()
# Exit-notify threads
######################################################################
# Exit-notify threads
######################################################################
-exitcondition = Condition(Lock())
-exitthreads = []
inited = 0
def initexitnotify():
inited = 0
def initexitnotify():
an ExitNotifyThread, or else an infinite loop may result. Furthermore,
the monitor will hold the lock all the while the other thread is waiting.
"""
an ExitNotifyThread, or else an infinite loop may result. Furthermore,
the monitor will hold the lock all the while the other thread is waiting.
"""
- global exitcondition, exitthreads
- exitcondition.acquire()
- try:
- while not len(exitthreads):
- exitcondition.wait(1)
-
- while len(exitthreads):
- callback(exitthreads.pop(0)) # Pull off in order added!
- finally:
- exitcondition.release()
+ callback(exitthreads.get(True))
+ exitthreads.task_done()
def threadexited(thread):
"""Called when a thread exits."""
def threadexited(thread):
"""Called when a thread exits."""
"""This class is designed to alert a "monitor" to the fact that a thread has
exited and to provide for the ability for it to find out why."""
def run(self):
"""This class is designed to alert a "monitor" to the fact that a thread has
exited and to provide for the ability for it to find out why."""
def run(self):
- global exitcondition, exitthreads, profiledir
+ global exitthreads, profiledir
self.threadid = thread.get_ident()
try:
if not profiledir: # normal case
self.threadid = thread.get_ident()
try:
if not profiledir: # normal case
self.setExitCause('NORMAL')
if not hasattr(self, 'exitmessage'):
self.setExitMessage(None)
self.setExitCause('NORMAL')
if not hasattr(self, 'exitmessage'):
self.setExitMessage(None)
- exitcondition.acquire()
- exitthreads.append(self)
- exitcondition.notify()
- exitcondition.release()
+
+ exitthreads.put(self, True)
def setExitCause(self, cause):
self.exitcause = cause
def setExitCause(self, cause):
self.exitcause = cause