- What are the minimum requirements?
- Does flup work under Windows?
- Are there any database-backed SessionStores?
- Old sessions aren't being deleted…
- I'm getting a 404 or I'm not finding my application at the expected place …
- How do I set the domain or expires parameters of the cookie generated …
- Is there any documentation?
- What's the difference between flup's fcgi module and your previous …
- I have problems with flup and dynamic (web server-launched) FastCGI …
- Calling WSGIServer.run from an imported module
- I get assertion errors when passing Unicode headers/responses to flup. …
Frequently Asked Questions
What are the minimum requirements?
Officially, flup requires Python 2.4 or greater. However, most modules will work with Python 2.3 with the exception of the forked servers. To use the forked servers under Python 2.3, you will need to install eunuchs.
Does flup work under Windows?
flup is not officially supported (that is, supported by me) under Windows. The most significant compatibility issues are in the servers. However, the threaded servers reportedly work fine. (Although some special care might have to be taken, e.g. binding to a TCP port in the case of the fcgi module.) Better luck may be had by using a Cygwin-compiled Python interpreter. Of course, I'll take patches to improve Windows compatibility as long as baseline functionality isn't affected.
Are there any database-backed SessionStores?
Yes, thanks to Luke Arno. See dbstore.
Old sessions aren't being deleted…
All of the SessionStore implementations have a .periodic method which is meant to be called periodically. I left it up to the developer (you) to decide where and how often to call it. The most typical way is to set up a thread:
store = ...SessionStore() # Whichever SessionStore import thread, time def _cleanup(): while True: store.periodic() time.sleep(300) thread.start_new_thread(_cleanup, ())
Note that all implementations should have their .periodic method called, including MemorySessionStore.
I'm getting a 404 or I'm not finding my application at the expected place when using flup servers
If your application isn't mounted at the host's root, then you may have to specify the scriptName parameter to the server. For example, if your application is at http://localhost/test
from flup.server.fcgi import WSGIServer WSGIServer(app, scriptName='/test').run()
The scriptName, if non-empty, must start with a forward-slash and must not end with one.
How do I set the domain or expires parameters of the cookie generated by SessionMiddleware?
SessionMiddleware (actually SessionService) takes a keyword parameter cookieAttributes which is a dict of additional key/value pairs to apply to the underlying cookie. (See Morsel Objects.)
For example, to explicitly set the domain:
app = SessionMiddleware(sessionStore, app, cookieAttributes={ 'domain': '.example.com'})
To change the cookie expiration on a per-user basis:
service = environ['com.saddi.service.session'] service.cookieAttributes['expires'] = 7*86400 # 7 days
Is there any documentation?
The best documentation is the source. :) But no, there is no convenient, online-accessible documentation. However, most of the public classes/methods are pydoc-annotated.
What's the difference between flup's fcgi module and your previous fcgi.py?
Feature-wise, very little, as I do try to keep both implementations in sync. The most significant difference is that flup's fcgi module uses thread pooling, fcgi.py simply starts a new thread for each connection/request. flup's code is refactored and modularized, to minimize duplicated code between all 6 servers.
However, I'd rather not have to maintain fcgy.py anymore. ;)
I have problems with flup and dynamic (web server-launched) FastCGI applications
So far, Dreamhost users seem to be the most vocal about this. :) I really don't know what to say. The issue stems from the fact that the FastCGI app takes too long to start, so the web server starts another instance (or two... or five). Using the simpler fcgi.py mentioned above alleviates the issue somewhat, but the problem is still there (and you will still see it under heavy server load).
Try another WSGI-FastCGI adapter, as there are others now. See http://wsgi.org/wsgi/Servers.
Or for another alternative, try the procedure outlined at DynamicToStaticFastCGI.
Calling WSGIServer.run from an imported module
This is not recommended as it causes problems with the cgitb module in threaded servers. It is apparently a Python/cgitb issue. See #12.
I get assertion errors when passing Unicode headers/responses to flup. What gives?
Your application (or possibly middleware) is broken. This is what the WSGI spec says about Unicode:
http://www.python.org/dev/peps/pep-0333/#unicode-issues
In other words, all strings passing through WSGI must be of type str. They cannot be of type unicode nor can they be a subclass of str.