Skip to content

Commit

Permalink
synchronize thread start/stop methods
Browse files Browse the repository at this point in the history
  • Loading branch information
zopyx committed Aug 19, 2007
1 parent 12387d8 commit a52a89e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion MailHost.py
Expand Up @@ -20,6 +20,7 @@
import time
import logging
from cStringIO import StringIO
from threading import Lock

import Acquisition
import OFS.SimpleItem
Expand All @@ -38,6 +39,7 @@
QueueProcessorThread

from interfaces import IMailHost
from decorator import synchronized

queue_threads = {} # maps MailHost path -> queue processor threada

Expand Down Expand Up @@ -74,8 +76,10 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
smtp_pwd=''
smtp_queue = False
smtp_queue_directory = '/tmp'
lock = Lock()

timeout=1.0
# timeout=1.0 # unused?


manage_options=(
(
Expand Down Expand Up @@ -187,6 +191,7 @@ def _makeMailer(self):
self.smtp_pwd or None
)

@synchronized(lock)
def _stopQueueProcessorThread(self):
""" Stop thread for processing the mail queue """

Expand All @@ -200,6 +205,7 @@ def _stopQueueProcessorThread(self):
del queue_threads[path]
LOG.info('Thread for %s stopped' % path)

@synchronized(lock)
def _startQueueProcessorThread(self):
""" Start thread for processing the mail queue """

Expand Down
30 changes: 30 additions & 0 deletions decorator.py
@@ -0,0 +1,30 @@
##############################################################################
#
# 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

0 comments on commit a52a89e

Please sign in to comment.