[Zope3-checkins] CVS: Zope3/src/zope/app/mail - service.py:1.8
Jim Fulton
jim at zope.com
Mon Sep 22 18:37:24 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/mail
In directory cvs.zope.org:/tmp/cvs-serv31297/src/zope/app/mail
Modified Files:
service.py
Log Message:
Added a stop method to QueueProcessorThread to allow threads
to be stopped. This was needed so we don't leave threads behind when
testing.
=== Zope3/src/zope/app/mail/service.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/mail/service.py:1.7 Sun Aug 17 02:07:13 2003
+++ Zope3/src/zope/app/mail/service.py Mon Sep 22 18:37:23 2003
@@ -26,7 +26,6 @@
from random import randrange
from time import strftime
from socket import gethostname
-from time import sleep
from zope.interface import implements
from zope.app.interfaces.mail import IDirectMailService, IQueuedMailService
@@ -119,6 +118,11 @@
mail:queuedService directive handler.
"""
log = logging.getLogger("QueueProcessorThread")
+ __stopped = False
+
+ def __init__(self):
+ threading.Thread.__init__(self)
+ self.__event = threading.Event()
def setMaildir(self, maildir):
"""Set the maildir.
@@ -160,6 +164,7 @@
return fromaddr, toaddrs, rest
def run(self, forever=True):
+
while True:
for filename in self.maildir:
try:
@@ -181,8 +186,14 @@
fromaddr, ", ".join(toaddrs), exc_info=1)
else:
if forever:
- sleep(3)
+ self.__event.wait(3)
+ if self.__stopped:
+ return
# A testing plug
if not forever:
break
+
+ def stop(self):
+ self.__stopped = True
+ self.__event.set()
More information about the Zope3-Checkins
mailing list