ValueError: the signal only works in the main thread - Django - mod_wsgi

I am trying to execute a shell command and kill it with the python signal module.

I know that signals only work with the main thread, so I start the Django development server with

python manage.py runserver --nothreading --noreload 

and it works great.

But when I deploy the django application with Apache / mod_wsgi, it shows the following error:

 [Fri Sep 12 20:07:00 2014] [error] response = function.call(request, **data) [Fri Sep 12 20:07:00 2014] [error] File "/Site/cloud/lib/python2.6/site-packages/dajaxice/core/Dajaxice.py", line 18, in call [Fri Sep 12 20:07:00 2014] [error] return self.function(*args, **kwargs) [Fri Sep 12 20:07:00 2014] [error] File "/Site/cloud/soc/website/ajax.py", line 83, in execute [Fri Sep 12 20:07:00 2014] [error] data = scilab_run(code, token, book_id, dependency_exists) [Fri Sep 12 20:07:00 2014] [error] File "/Site/cloud/soc/website/helpers.py", line 58, in scilab_run [Fri Sep 12 20:07:00 2014] [error] output = task.run().communicate()[0] [Fri Sep 12 20:07:00 2014] [error] File "/Site/cloud/soc/website/timeout.py", line 121, in run [Fri Sep 12 20:07:00 2014] [error] lambda sig,frame : os.killpg(self.pgid,self.timeoutSignal) ) [Fri Sep 12 20:07:00 2014] [error] ValueError: signal only works in main thread 

Here is my apache virtual host setup:

 WSGIDaemonProcess testcloud display-name=scilab_cloud user=apache group=apache threads=1 WSGIProcessGroup testcloud WSGIScriptAlias / /Site/cloud/soc/soc/wsgi.py WSGIImportScript /Site/cloud/soc/soc/wsgi.py process-group=testcloud application-group=%{GLOBAL} 

I also have the following settings outside virtualhost in httpd.conf:

 WSGIRestrictSignal Off WSGISocketPrefix /var/run/wsgi 

Here is a link to a program that uses a signal and one that I use in my django application.

Any help would be greatly appreciated.

+7
python django signals apache mod-wsgi
source share
1 answer

I'm not sure if this can be done easily, or at least not with mod_wsgi. The decision about whether or not to stream is the sum of the build parameters and runtime in both apache and mod_wsgi, both of which are set by default for streaming.

I would point you to the docs about this, but I can only post two links, so I think it's better to spend them on proposing a solution:

I had decent experience working with shell commands from python with sh , which even has an asynchronous executable. Perhaps you can run your python code using a shell command, and handle the callback object if necessary.

Or, even better, since sh asks you to have some concerns when processing signals, you can simply start it without an asynchronous execution module, but in another process with multiprocessing.Proces , which will give you a Process object that you can simply kill with object.terminate()

0
source share

All Articles