Mike Looijmans
mike.looijmans at asml.com
Mon Jun 2 07:40:29 EST 2003
Probably, the freeze is because apache 1.3 doesn't support threading. I guess the same applies to the "req" object as most GUIs: Only access the Request object from the thread that created it. It might work if you make the thread object like this: def run(self): self.result = "Hello from thread!\n" then after the join, use "req.write(w.result)" to output the result from the thread. Solution would be to remove the threading, since it is useless in a HTTP server anyway. The client has to wait for the data to be sent back anyway. If you want to use another handler for parts of the message, just send the client a "304" (redirect) response, or (if you feel like having fun) send a HTTP request to your own HTTP server, which will use another process or thread to handle it. I use HTTP client connections inside the HTTP server on our replication server (which acts as a sort of 'proxy': work on a replication slave of the MySQL master database and also caches files) to fetch files from the master server. -- Mike Looijmans -----Original Message----- From: Russell Yanofsky <rey4 at columbia.edu> To: mod_python at modpython.org <mod_python at modpython.org> Date: Sunday, June 01, 2003 11:34 PM Subject: [mod_python] Mod_Python 2.7.8 and threading >Hi, I'm trying to get write a multithreaded script to run under mod_python >and apache 1.3 on linux, but the script seems to just freeze up at the point >of thread creation leaving the http connection open but not doing anything >else. > >I isolated the problem in a little test script: > >-- begin mptest.py -- >from mod_python import apache > >def handler(req): > w = Worker(req) > req.write("Starting thread...\n") > w.start() > req.write("Joining thread...\n") > w.join() > req.write("Done.\n") > return apache.OK > >import threading > >class Worker(threading.Thread): > def __init__(self, req): > self.req = req > threading.Thread.__init__(self) > > def run(self): > self.req.write(" Hello from thread!\n") >-- end mptest.py -- > >-- begin .htaccess -- >AddHandler python-program .py >PythonHandler mptest >PythonDebug On >-- end .htaccess -- > >The script runs fine on a windows box running Apache 2.0.46, Mod_Python >3.0.3, and Python 2.2.2, but it freezes on my linux server running Apache >1.3.27, Mod_Python 2.7.8, and Python 2.2.2. > >The place where it seems to freeze is at w.start(). If you comment that line >out, it does complete execution. Is this problem a bug in mod_python, or >have I done something wrong? > >- Russ > > > >_______________________________________________ >Mod_python mailing list >Mod_python at modpython.org >http://mailman.modpython.org/mailman/listinfo/mod_python > > >
|