I was pulling my hair out yesterday, trying to get my Django
application's forms working on both the development server, and
running under Twisted trunk.
POST variables were not arriving in the REQUEST object where they
belonged, but only under Twisted.
So, I did the only logical thing; I made a completely isolated test
case, now available at:
Along the way, I finally decided to start over from scratch with a
brand new --no-site-packages virtualenv, then installed only what was
The repository shows what I think may be the simplest way to run
Django under Twisted WSGI which I pretty much stole wholesale from the
Pinax WSGI setup.
I'll be writing a blog post with a blow-by-blow shortly which I'll
post when it's done but, for now, this is a very clear, and dead
simple way to run Django under Twisted WSGI.
Please note: you *must* be running a Twisted trunk checkout because
some WSGI bugs have been fixed since the most recent release.
Date: Fri, 30 Oct 2009 17:38:12 +0800
From: Crispin Wellington <cwellington(a)ccg.murdoch.edu.au>
Subject: [Twisted-Python] Using a custom reactor in twisted trial for
>I am using twisted trial to run test cases for an application. The
>application however uses stackless python and has a custom stackless
>reactor. I implemented this reactor like this...
For better or worse, much of what you have discussed have been fleshed out about two years ago in this mailing list and in stackless. Also I outline strategies in the PyCon 2008 talk "Adventures in Stackless Twisted Integration." Personally, I don't know why more people don't use Stackless with Twisted.
1) Based on what I have seen, you don't need to write a custom reactor (I still remember Glyph setting me straight on that one). At least for what you are doing :-).
2) Use task.loopingCall to make the reactor periodically yield.
l = task.LoopingCall(stackless.schedule)
however there is some weird interaction between Stackless Python 2.6 and Twisted so you may have to do
or play with the recursionlimit variable. I have not gotten to the bottom of that problem.
I was facing the issue as noted here http://twistedmatrix.com/trac/ticket/3629.
As I see, python 2.5 can be build with pysqlite2.1.3 and sqlite 3.0.8 or later.
However, support for a connection to be moved across multiple threads
was added to sqlite at version3.3.1.
Last comment in the ticket says, the module is just overprotective.
Which module is he referring to and why is it said that it is overprotective?
Is he referring to the pysqlite module?
He says using check_same_thread=False is safe, is he saying it
specifically in the twisted's context?
Is it really safe even if I am using sqlite version between 3.0.8 to 3.3.1?
>>>>> "Brian" == Brian Granger <ellisonbg.net(a)gmail.com> writes:
Brian> I looked at deferLater, but am not using it right now. The sleep
Brian> function I am using is basically the same as this - in my case
Brian> "sleep" turned out to be a little simpler because I don't have to
Brian> create and pass the clock around. But I will probably use
Brian> deferLater for this same purpose in the future as well.
Forgive me for butting in, but.... why :-)
Importing the reactor is no big deal, and if you use task.deferLater, apart
from not having to write any code you also have the advantage of being able
to pass it a result that the deferred will be called with.
For this reason you can also put a task.deferLater result into a callback
chain to achieve an async sleep and it will duly pass the result along. E.g.:
from twisted.internet import reactor, task, defer
d = somethingReturningADeferred()
d.addCallback(lambda x: task.deferLater(reactor, 5.0, defer.passthru, x))
I am very interested in the improvements to the Twisted Web Client
portion of Twisted and have been wanting to review two tickets/
branches in particular; 3987 and 886.
Today I finally got around to getting the branches checked out and
merged, with some great help from `ivan` on IRC and, wrote a blog post
detailing exactly how to do it.
It uses Git instead of Subversion for the actual merges so it didn't
suck anywhere as much as it would have with Subversion alone.
Comments/corrections always welcome.
>>>>> "Steve" == Steve Steiner (listsin) <listsin(a)integrateddevcorp.com> writes:
Steve> curl http://localhost/w3c-validator/check <-- returns HTML code
Steve> any browser to http://localhost/w3c-validator/check <-- returns HTML code
Steve> t.w.c.getPage("http://localhost/w3c-validator/check") <-- 404
Steve> wget http://localhost/w3c-validator/check <-- 404
Steve> So what the heck is the difference in how these things resolve that
When you say 404, do you really mean that you get a 404? Or are you just
saying that to informally tell us that it doesn't work?
If the former, then it seems this has nothing to do with DNS and host
names. The connection is being made in all cases. It looks like there's
something different about the HTTP requests that causes the server to react
differently. You're writing the server, correct? Can you log output?
If the latter, then I guess you really mean that the connection fails.
I can browse to either URL in any browser, getPage() works fine on the
external address, 404's on the localhost address.
Any insight greatly appreciated; this is about as simple a test case
as there can be and I'm mystified as to why it's not working. Of
course, that probably means I'll feel like a complete moron when
someone clops me on the head with the answer, but I can deal with
Just in case it gets mutilated by mail:
from twisted.web import client
print "Error:", failure.getErrorMessage()
if __name__ == "__main__":
from twisted.internet import reactor
# postRequest = client.getPage("http://localhost/w3c-validator/check
postRequest = client.getPage("http://validator.w3.org/check")
I have a client server model in twisted, where the server spawns a thread (
basically a test script in python that runs for about 20 mins)
I want to track the progress of the thread, and send the progress to the
So, I write something like this in my server:
parent_conn, child_conn = Pipe()
thread = Process(target = start_test.main_func, args=(SCRIPT_PATH,
TEMP_OUTPUT_PATH, self.output_name, child_conn))
response = parent_conn.recv()
print response //prints like: initialization done
response = parent_conn.recv()
print response // configuration done
But the transport.write calls don't send at the same time. instead they wait
for the thread to finish (coz of thread.join) and then append all the
response and send it back; like "initialization doneconfiguration
thereby defeating the purpose of creating a thread.
How do I give the control to the reactor to write the data back, and still
keep the thread running?
or is there any other way these kinda of progress can be tracked ?
I am kinda stuck with this :(
Run the example *not* as root, then it will work. sys.path is
different for the root user, that is the problem.
On Tue, Oct 27, 2009 at 11:17 AM, Alfredo Veltri
> Hi Alex,
> i'm trying with hotdot.
> i receive the following errors. Would help me about that?
> Thanks in advance.
> root@myhome:/var/www/clemesha-hotdot-522849b/djangoweb# cd
> root@myhome:/var/www/clemesha-hotdot-522849b# ls
> djangoweb README.rst realtime server.py static
> root@myhome:/var/www/clemesha-hotdot-522849b# twistd -ny
> Traceback (most recent call last):
> , line 690, in run
> , line 23, in runApp
> , line 411, in run
> self.application = self.createOrGetApplication()
> , line 494, in createOrGetApplication
> application = getApplication(self.config, passphrase)
> --- <exception caught here> ---
> , line 505, in getApplication
> application = service.loadApplication(filename, style,
> , line 390, in loadApplication
> application = sob.loadValueFromFile(filename,
> 'application', passphrase)
> , line 210, in loadValueFromFile
> exec fileObj in d, d
> File "server.py", line 25, in <module>
> from djangoweb.twisted_wsgi import get_root_resource
> exceptions.ImportError: No module named
> Failed to load application: No module named