Commit b1d3757c authored by Kevin Deldycke's avatar Kevin Deldycke

First Klaus' patch to make zope start nicer

git-svn-id: 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 47eea1f9
......@@ -53,15 +53,16 @@ class TimerService(SimpleItem):
for path in self._subscribers]
tick = time.time()
prev_tick = tick - interval
next_tick = tick + interval
# prev_tick = tick - interval
# next_tick = tick + interval
LOG('TimerService', INFO, 'Ttimer tick at %s\n'%time.ctime(tick))
# LOG('TimerService', INFO, 'Ttimer tick at %s\n'%time.ctime(tick))
for subscriber in subscriptions:
interval, DateTime(tick), DateTime(prev_tick), DateTime(next_tick))
# subscriber.process_timer(
# interval, DateTime(tick), DateTime(prev_tick), DateTime(next_tick))
subscriber.process_timer(tick, interval)
LOG('TimerService', ERROR, 'Process timer error', error = sys.exc_info())
......@@ -77,6 +78,12 @@ class TimerService(SimpleItem):
self._subscribers = subscribers
def unsubscribeByPath(self, path):
subscribers = self._subscribers
if path in subscribers:
self._subscribers = subscribers
def unsubscribe(self, ob):
""" """
path = '/'.join(ob.getPhysicalPath())
......@@ -94,12 +101,14 @@ class TimerService(SimpleItem):
def manage_removeSubscriptions(self, no, REQUEST=None):
""" """
subs = self.listAllSubscriptions()
subs = self.lisSubscriptions()
remove_list = [subs[n] for n in [int(n) for n in no]]
for subs, event, fl in remove_list:
self.unsubscribe( subs, event_type=event )
for sub in remove_list:
if REQUEST is not None:
......@@ -6,7 +6,10 @@ __version__ = 'TimerServer for Zope 0.1'
import traceback
import thread
import sys, os, errno, time
import sys, os, errno, time, socket
import ZPublisher.Client
from StringIO import StringIO
from zLOG import LOG, INFO
......@@ -14,9 +17,10 @@ from ZServer.PubCore import handle
from ZPublisher.BaseRequest import BaseRequest
from ZPublisher.BaseResponse import BaseResponse
from ZPublisher.HTTPRequest import HTTPRequest
from ZPublisher import Client
class TimerServer:
def __init__(self, module, interval=600):
def __init__(self, module, interval=5):
self.module = module
self.interval = interval
......@@ -35,6 +39,34 @@ class TimerServer:
'\tInterval: %s seconds.\n'%(time.ctime(time.time()), interval))
def run(self):
# wait until the zhttp_server exist in socket_map
# because TimerService has to be started after the Zope HTTPServer
from asyncore import socket_map
while 1:
for k, v in socket_map.items():
if hasattr(v, 'port'):
# see Zope/lib/python/App/ def getServers(self)
type = str(getattr(v, '__class__', 'unknown'))
if type == 'ZServer.HTTPServer.zhttp_server':
port = v.port
if port:
ip = socket.gethostbyname(socket.gethostname())
# To be very sure, try to connect to the HTTPServer
# and only start after we are able to connect
while 1:
try:'http://%s:%s' %(ip, port))
except ValueError:
module = self.module
interval = self.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