Skip to content

Commit f77a664

Browse files
author
Richard Jones
committed
disable forking server when os.fork() not available [SF#938586]
1 parent 8647560 commit f77a664

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ are given with the most recent entry first.
55
Fixed:
66
- sqlite migration drops some journal information (thanks David Linke)
77
- user editing Role entry help text always appears
8+
- disable forking server when os.fork() not available (sf bug 938586)
89

910

1011
2004-04-18 0.7.0b3

roundup/cgi/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.170 2004-04-05 06:13:42 richard Exp $
1+
# $Id: client.py,v 1.171 2004-04-20 21:57:10 richard Exp $
22

33
"""WWW request handler (also used in the stand-alone server).
44
"""
@@ -97,7 +97,9 @@ class Client:
9797
# pagesize, startwith
9898

9999
def __init__(self, instance, request, env, form=None):
100-
hyperdb.traceMark()
100+
if __debug__:
101+
hyperdb.traceMark()
102+
self.start = time.time()
101103
self.instance = instance
102104
self.request = request
103105
self.env = env
@@ -140,7 +142,6 @@ def __init__(self, instance, request, env, form=None):
140142
self.additional_headers = {}
141143
self.response_code = 200
142144

143-
144145
def main(self):
145146
''' Wrap the real main in a try/finally so we always close off the db.
146147
'''
@@ -212,6 +213,7 @@ def inner_main(self):
212213

213214
# render the content
214215
self.write(self.renderContext())
216+
215217
except SeriousError, message:
216218
self.write(str(message))
217219
except Redirect, url:
@@ -513,6 +515,9 @@ def renderContext(self):
513515
# let the template render figure stuff out
514516
result = pt.render(self, None, None, **args)
515517
self.additional_headers['Content-Type'] = pt.content_type
518+
if os.environ.get('CGI_SHOW_TIMING', ''):
519+
s = '<p>Time elapsed: %fs</p></body>'%(time.time()-self.start)
520+
result = result.replace('</body>', s)
516521
return result
517522
except templating.NoTemplate, message:
518523
return '<strong>%s</strong>'%message

roundup/scripts/roundup_server.py

Lines changed: 11 additions & 6 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.45 2004-04-09 01:31:16 richard Exp $
20+
$Id: roundup_server.py,v 1.46 2004-04-20 21:57:16 richard Exp $
2121
"""
2222
__docformat__ = 'restructuredtext'
2323

@@ -238,11 +238,19 @@ def error():
238238
exc_type, exc_value = sys.exc_info()[:2]
239239
return _('Error: %s: %s' % (exc_type, exc_value))
240240

241+
# See whether we can use the forking server
242+
if hasattr(os, 'fork'):
243+
class server_class(SocketServer.ForkingMixIn, BaseHTTPServer.HTTPServer):
244+
pass
245+
else:
246+
server_class = BaseHTTPServer.HTTPServer
247+
241248
try:
242249
import win32serviceutil
243250
except:
244251
RoundupService = None
245252
else:
253+
246254
# allow the win32
247255
import win32service
248256
import win32event
@@ -460,12 +468,9 @@ def run(port=PORT, success_message=None):
460468
# obtain server before changing user id - allows to use port <
461469
# 1024 if started as root
462470
address = (hostname, port)
463-
server_klass = BaseHTTPServer.HTTPServer
464-
class server_klass(SocketServer.ForkingMixIn,
465-
BaseHTTPServer.HTTPServer):
466-
pass
471+
467472
try:
468-
httpd = server_klass(address, RoundupRequestHandler)
473+
httpd = server_class(address, RoundupRequestHandler)
469474
except socket.error, e:
470475
if e[0] == errno.EADDRINUSE:
471476
raise socket.error, \

tools/load_tracker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /usr/bin/env python
2-
# $Id: load_tracker.py,v 1.1 2004-04-20 05:47:33 richard Exp $
2+
# $Id: load_tracker.py,v 1.2 2004-04-20 21:57:29 richard Exp $
33

44
'''
55
Usage: %s <tracker home> <N>
@@ -71,6 +71,8 @@
7171
priority=random.choice(priorities),
7272
status=random.choice(statuses),
7373
assignedto=random.choice(users))
74+
if i%100:
75+
db.commit()
7476
print
7577

7678
db.commit()

0 commit comments

Comments
 (0)