Skip to content

Commit a11410f

Browse files
author
Alexander Smishlajev
committed
added multiprocess mode "debug" - run single process...
...and don't cache tracker instances or compiled templates; preload all trackers unless in "debug" mode (thanks donfu)
1 parent 361c0fb commit a11410f

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

roundup/scripts/roundup_server.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
"""Command-line script that runs a server over roundup.cgi.client.
1919
20-
$Id: roundup_server.py,v 1.71 2004-10-30 08:43:06 a1s Exp $
20+
$Id: roundup_server.py,v 1.72 2004-11-02 09:07:08 a1s Exp $
2121
"""
2222
__docformat__ = 'restructuredtext'
2323

@@ -52,7 +52,10 @@
5252
DEFAULT_PORT = 8080
5353

5454
# See what types of multiprocess server are available
55-
MULTIPROCESS_TYPES = ["none"]
55+
# Note: the order is important. Preferred multiprocess type
56+
# is the last element of this list.
57+
# "debug" means "none" + no tracker/template cache
58+
MULTIPROCESS_TYPES = ["debug", "none"]
5659
try:
5760
import thread
5861
except ImportError:
@@ -65,8 +68,32 @@
6568

6669
class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
6770
TRACKER_HOMES = {}
71+
TRACKERS = None
6872
LOG_IPADDRESS = 1
6973

74+
def get_tracker(self, name):
75+
"""Return a tracker instance for given tracker name"""
76+
# Note: try/except KeyError works faster that has_key() check
77+
# if the key is usually found in the dictionary
78+
#
79+
# Return cached tracker instance if we have a tracker cache
80+
if self.TRACKERS:
81+
try:
82+
return self.TRACKERS[name]
83+
except KeyError:
84+
pass
85+
# No cached tracker. Look for home path.
86+
try:
87+
tracker_home = self.TRACKER_HOMES[name]
88+
except KeyError:
89+
raise client.NotFound
90+
# open the instance
91+
tracker = roundup.instance.open(tracker_home)
92+
# and cache it if we have a tracker cache
93+
if self.TRACKERS:
94+
self.TRACKERS[name] = tracker
95+
return tracker
96+
7097
def run_cgi(self):
7198
""" Execute the CGI command. Wrap an innner call in an error
7299
handler so all errors can be caught.
@@ -158,12 +185,6 @@ def inner_run_cgi(self):
158185
self.wfile.write('Moved Permanently')
159186
return
160187

161-
if self.TRACKER_HOMES.has_key(tracker_name):
162-
tracker_home = self.TRACKER_HOMES[tracker_name]
163-
tracker = roundup.instance.open(tracker_home)
164-
else:
165-
raise client.NotFound
166-
167188
# figure out what the rest of the path is
168189
if len(l_path) > 2:
169190
rest = '/'.join(l_path[2:])
@@ -193,7 +214,8 @@ def inner_run_cgi(self):
193214
env['SERVER_PORT'] = str(self.server.server_port)
194215
env['HTTP_HOST'] = self.headers['host']
195216

196-
# do the roundup thang
217+
# do the roundup thing
218+
tracker = self.get_tracker(tracker_name)
197219
tracker.Client(tracker, self, env).main()
198220

199221
def address_string(self):
@@ -376,10 +398,18 @@ def get_server(self):
376398
sys.stdout = sys.stderr = open(self["LOGFILE"], 'a', 0)
377399
# we don't want the cgi module interpreting the command-line args ;)
378400
sys.argv = sys.argv[:1]
401+
# preload all trackers unless we are in "debug" mode
402+
tracker_homes = self.trackers()
403+
if self["MULTIPROCESS"] == "debug":
404+
trackers = None
405+
else:
406+
trackers = dict([(name, roundup.instance.open(home))
407+
for (name, home) in tracker_homes])
379408
# build customized request handler class
380409
class RequestHandler(RoundupRequestHandler):
381410
LOG_IPADDRESS = not self["LOG_HOSTNAMES"]
382-
TRACKER_HOMES = dict(self.trackers())
411+
TRACKER_HOMES = dict(tracker_homes)
412+
TRACKERS = trackers
383413
# obtain request server class
384414
if self["MULTIPROCESS"] not in MULTIPROCESS_TYPES:
385415
print _("Multiprocess mode \"%s\" is not available, "

0 commit comments

Comments
 (0)