Commit bbb46d26 authored by Julien Muchembled's avatar Julien Muchembled

TimerServer: code cleanup

parent 2ff798bd
...@@ -3,10 +3,7 @@ ...@@ -3,10 +3,7 @@
# Authors: Nik Kim <fafhrd@legco.biz> # Authors: Nik Kim <fafhrd@legco.biz>
from App.ImageFile import ImageFile from App.ImageFile import ImageFile
from AccessControl import ModuleSecurityInfo, allow_module from .TimerService import TimerService, current_version
from AccessControl.Permissions import view
from TimerService import TimerService, current_version
misc_ = { 'timer_icon.gif': misc_ = { 'timer_icon.gif':
ImageFile('zpt/timer_icon.gif', globals())} ImageFile('zpt/timer_icon.gif', globals())}
......
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# -*- Mode: Python; py-indent-offset: 4 -*- # -*- Mode: Python; py-indent-offset: 4 -*-
# Authors: Nik Kim <fafhrd@legco.biz> # Authors: Nik Kim <fafhrd@legco.biz>
__version__ = 'TimerServer for Zope 0.1'
import traceback import errno, logging, os, re, socket, sys, threading, time, traceback
import thread
import re
import sys, os, errno, time, socket
from functools import partial from functools import partial
from urlparse import urlsplit from urlparse import urlsplit
from StringIO import StringIO from StringIO import StringIO
from zLOG import LOG, INFO
from ZPublisher.BaseRequest import BaseRequest
from ZPublisher.BaseResponse import BaseResponse from ZPublisher.BaseResponse import BaseResponse
from ZPublisher.HTTPRequest import HTTPRequest from ZPublisher.HTTPRequest import HTTPRequest
from ZPublisher.HTTPResponse import HTTPResponse from ZPublisher.HTTPResponse import HTTPResponse
import ZPublisher.HTTPRequest import ZPublisher.HTTPRequest
class TimerServer: logger = logging.getLogger('TimerServer')
class TimerServer(threading.Thread):
def __init__(self, module, interval=600): def __init__(self, module, interval=600):
super(TimerServer, self).__init__()
self.daemon = True
self.module = module self.module = module
self.interval = interval self.interval = interval
self.start()
sync = thread.allocate_lock() logger.info('Service initialized with interval of %s second(s).',
interval)
self._a = sync.acquire
self._r = sync.release
self._a()
thread.start_new_thread(self.run, ())
self._r()
LOG('ZServer', INFO,
'Timer server started at %s\n'
'\tInterval: %s seconds.\n'%(time.ctime(time.time()), interval))
def run(self): def run(self):
try: try:
...@@ -104,7 +91,7 @@ class TimerServer: ...@@ -104,7 +91,7 @@ class TimerServer:
module = self.module module = self.module
interval = self.interval interval = self.interval
LOG('ZServer', INFO, 'Timerserver ready, starting timer services.') logger.info('Service ready.')
while 1: while 1:
time.sleep(interval) time.sleep(interval)
......
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