开发者

Python signals hosted on WSGI

I'm using the python signals library to kill a function if it runs longer than a set period of time.

It works well in my tests but when hosted on the server I get the following error

"signal only works in main thread"

I have set the W开发者_JS百科SGI signals restriction to be off in my httpd.conf

WSGIRestrictSignal Off

as described http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Registration_Of_Signal_Handlers

I'm using the functions from the recipe described here http://code.activestate.com/recipes/307871/

Not sure what I'm doing wrong. Is there a way to ensure that the signals are called in the main thread?


The only time any code under Apache/mod_wsgi runs as main thread is when a WSGI script file is being imported via WSGIImportScript or equivalent methods. Although one could use that method to register the signal handler from the main thread, it will be of no use as all subsequent requests are serviced via secondary threads and never the main thread. As a consequence, I don't think your signal handler will ever run as recollect that it can only run if the main thread is actually doing something, and that will not be the case as the main thread, will be blocked in Apache/mod_wsgi simply waiting for the process to be shutdown.

What is the operation doing that you are trying to kill? Doing it within context of web application, especially if web application is multi threaded probably isn't a good idea.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜