Opened 7 years ago

Closed 6 years ago

#8742 closed (invalid)

Windows support of FastCGI feature

Reported by: anonymous Owned by: nobody
Component: Uncategorized Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Django FastCGI cannot be used on Windows, and possibly other non-Unix environments.

Currently the FastCGI feature of Django (manage.py runfcgi) relies on the Python library 'flup', which relies on Unix-only socket functions (socket.socketpair(), socket.fromfd(), etc.) making it impossible to use the FastCGI feature of Django on non-Unix envs like Windows, and hence, making it impossible to serve Django with non-Apache (non-mod_python) httpds like lighttpd on non-Unix envs.

Possible solutions: The function socketpair() is unofficially implemented on Windows by a recipe. (http://code.activestate.com/recipes/525487/) Committing this patch to the flup project is not a hard work. However, the function fromfd() has nothing like that. There is a patch enabling its Windows use (http://bugs.python.org/issue1378) but the patch is not yet applied on the Windows release, even on Python 2.6b2. Rewriting the FastCGI feature with python-fastcgi (http://pypi.python.org/pypi/python-fastcgi) could be a more work than flup, but then the feature can support Windows.

Unix environments, especially GNU/Linux, is of course better than Windows to be used as a web server, but there are some situations where Windows and FastCGI have to be used. It would be good to have Django FastCGI available on Windows.

Change History (6)

comment:1 follow-up: Changed 7 years ago by Daniel Pope <dan@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

flup (and by extension Django) does not officially support FastCGI on Windows.

However, according to the FAQ, threaded servers are reported to work under Windows; could you determine whether manage.py runfcgi method=threaded works?

We could add a note in the documentation drawing attention to this fact.

comment:2 in reply to: ↑ 1 Changed 7 years ago by anonymous

No, it doesn't work, resulting an AttributeError: 'module' object has no attribute 'fromfd'.

comment:3 Changed 7 years ago by anonymous

i mean, it 'still' doesn't work, even with method=threaded.

comment:4 Changed 7 years ago by Daniel Pope <dan@…>

The other thing I can suggest is to try AJP or SCGI. A quick grep shows no instances of fromfd or socketpair in the AJP server code.

comment:5 Changed 6 years ago by snaury

I can confirm that flup works on Windows and Apache, just not the way most people expect (due to principal differences between files and sockets on Windows). To make it work, you need to start your server like this in your dispatch.fcgi:

from django.core.servers.fastcgi import runfastcgi
runfastcgi(protocol="fcgi", method="threaded", daemonize="false", host="127.0.0.1", port=port)

Then in your httpd.conf you will need to make apache aware of your server:

FastCgiExternalServer <path-to-your-wwwroot>/dispatch.fcgi -host 127.0.0.1:<port>

Of course with this setup apache won't start your fastcgi server for you (and frankly, with the way python (or flup, I'm not sure) handles signals on Windows you DON'T want apache to start python servers for you, as it won't be able to kill them afterwards), you'll need to do it yourself separately. I, for example, run my fastcgi server as a Windows service (using win32service), which is even better since with this setup apache and fastcgi servers can run as different users.

comment:6 Changed 6 years ago by jacob

  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.
Back to Top