Commit 08dc5a38 authored by Andreas Jung's avatar Andreas Jung

synchronize thread start/stop methods

parent 1d037663
...@@ -20,6 +20,7 @@ import rfc822 ...@@ -20,6 +20,7 @@ import rfc822
import time import time
import logging import logging
from cStringIO import StringIO from cStringIO import StringIO
from threading import Lock
import Acquisition import Acquisition
import OFS.SimpleItem import OFS.SimpleItem
...@@ -38,6 +39,7 @@ from zope.sendmail.delivery import DirectMailDelivery, QueuedMailDelivery, \ ...@@ -38,6 +39,7 @@ from zope.sendmail.delivery import DirectMailDelivery, QueuedMailDelivery, \
QueueProcessorThread QueueProcessorThread
from interfaces import IMailHost from interfaces import IMailHost
from decorator import synchronized
queue_threads = {} # maps MailHost path -> queue processor threada queue_threads = {} # maps MailHost path -> queue processor threada
...@@ -74,8 +76,10 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager): ...@@ -74,8 +76,10 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
smtp_pwd='' smtp_pwd=''
smtp_queue = False smtp_queue = False
smtp_queue_directory = '/tmp' smtp_queue_directory = '/tmp'
lock = Lock()
timeout=1.0 # timeout=1.0 # unused?
manage_options=( manage_options=(
( (
...@@ -187,6 +191,7 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager): ...@@ -187,6 +191,7 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
self.smtp_pwd or None self.smtp_pwd or None
) )
@synchronized(lock)
def _stopQueueProcessorThread(self): def _stopQueueProcessorThread(self):
""" Stop thread for processing the mail queue """ """ Stop thread for processing the mail queue """
...@@ -200,6 +205,7 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager): ...@@ -200,6 +205,7 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
del queue_threads[path] del queue_threads[path]
LOG.info('Thread for %s stopped' % path) LOG.info('Thread for %s stopped' % path)
@synchronized(lock)
def _startQueueProcessorThread(self): def _startQueueProcessorThread(self):
""" Start thread for processing the mail queue """ """ Start thread for processing the mail queue """
......
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
Decorator(s)
$Id: MailHost.py 78992 2007-08-19 11:58:08Z andreasjung $
"""
def synchronized(lock):
""" Decorator for method synchronization. """
def wrapper(f):
def method(*args, **kw):
lock.acquire()
try:
return f(*args, **kw)
finally:
lock.release()
return method
return wrapper
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment