500 Internal Server Error with Python FCGI


#1

Hey,

My Python FCGI site just stopped working today. While investigating, I prepare two simple “hello, world” scripts: one in Perl and one in Python. I tried running them both from a command line and from a browser. Results are:

Perl in command-line: working
Perl in browser: working
Python in command-line: working
Python in browser: 500 Internal Server Error

Then I found out that the Python script sometimes works and sometimes doesn’t. I got this kind of trackbacks:


[shasta]$ REQUEST_METHOD=“GET” REQUEST_URI="/" QUERY_STRING="" SERVER_NAME=“www.atopowe.pl” SERVER_PORT=“80” SERVER_PROTOCOL=“HTTP” PATH_INFO="/" ./python_test.fcgi
Status: 200 OK
Content-Type: text/plain

Hello, world!
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:
[shasta]$

The above trackback is different every time. Sometimes there are no exceptions, sometimes it’s just one, some other times more exceptions. When trying to open this test script from a browser, the script probably dies before delivering any output.

Apache error.log contains:

[Sun Dec 24 17:29:37 2006] [error] [client xx.xx.xx.xx] FastCGI: comm with (dynamic) server “/home/xxx/yyy/python_test.fcgi” aborted: (first read) idle timeout (60 sec)
[Sun Dec 24 17:29:37 2006] [error] [client xx.xx.xx.xx] FastCGI: incomplete headers (0 bytes) received from server “/home/xxx/yyy/python_test.fcgi”

I don’t know how to investigate it further. Do you have any ideas? Where to look for more error messages?


#2

I’ve finally got some useful error message! I had to run a perl script, call a Python script from it, capture stderr and save it to a file. Result:

Traceback (most recent call last):
File “/home/myusername/mydomain.com/python_test.fcgi”, line 17, in ?
WSGIServer(test_app).run()
File “/home/myusername/fcgi.py”, line 1101, in run
thread.start_new_thread(conn.run, ())
thread.error: can’t start new thread


#3

I got my Django site working after switching the “threaded” mode to “prefork”:

[shasta]$ cat dispatch.fcgi
#!/usr/bin/python2.4
import sys, os
sys.path = [’/home/myuser/django_src’]
sys.path = [’/home/myuser/flup_src’]
sys.path = [’/home/myuser/django_projects’]

Set the DJANGO_SETTINGS_MODULE environment variable.

os.environ[‘DJANGO_SETTINGS_MODULE’] = “myapp.settings”

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method=“prefork”, daemonize=“false”)


#4

Surely no one was ignoring you, and forum traffic does seem to be way down with the holiday season. Thanks for the followup on your findings, Automatthias. That sort of thing is what makes this forum such a great resource.


#5

Do you know if it is possible to do the same kind of switch with Ruby On Rails application? from threaded to prefork?

my numerous 500 errors are probably from the same cause “unable to start a new thread”.

thanks for finding this up.