[Twisted-Python] You guys rock
Itamar Shtull-Trauring
twisted at itamarst.org
Wed Jul 31 14:59:31 EDT 2002
Barry A. Warsaw wrote:
> You guys have a big problem, because it was /way/ too easy to do! How
> are you going to make the big consulting bucks? :)
It's simple:
1. Get everyone to use it.
2. ???
3. MONEY!
> Three commands and I had an nntp server with a single newsgroup that
> was featured enough to connect Mozilla to, and to point Mailman's
> gateway at and actually get messages flowing back and forth.
> Congratulations!
Thanks - can we ask you for a quote for our 1.0 press release?
> I don't know if I'm going to do much else with Twisted, but I /would/
> like to try to figure out how to use it in a Mailman functional test
> suite. Right now I have some very ugly kludges to start up smtpd.py,
> send a message to it, and then suck the message out and compare the
> results with what I expect. As time permits I think I'll try to see
> how easy it would be to use Twisted in the role of smtpd.py, and add
> some tests for news as well as mail.
>
> The main issue is that unittest must be able to fire off the server,
> and extract information from it once the message has been propagated.
> My current test is pretty kludgy, but I'll spare you the asyncgore
> (sic). What would be ideal would be to be able to create a Twisted
> service but don't start it, send a message via Mailman machinery, then
> start the server and block on reading that message back from Twisted
> (with a timeout). I'd run Twisted with both an SMTP and NNTP server.
> Has anybody else thought about using Twisted in a unit or functional
> test situation?
Well, if the Twisted server is in the same process (you can run it in a
different thread) you have two alternatives:
reactor.listenTCP(8025, myFactory)
# we don't call reactor.run() here, instead we do
while testIsntDone:
reactor.iterate() # do a single iteration of the event loop
Or:
reactor.listenTCP(8025, myFactory)
reactor.run()
# when test is done it can call reactor.crash() to stop the event loop,
# which unlike reactor.stop() still allows us to run() again
In both cases you can use reactor.callLater() for a timoeut. We do both in
our unit tests (twisted.test) package, so you can find some examples there.
If you want to run Twisted in a different process, you may want to look at
how admin/accepttests does it. Basically you make a python script that has a
twisted.internet.app.Application instance called "application" at module
level, use the twistd command to run it (twistd -y myscript.py), and then
"kill `cat twistd.pid`" to shutdown the server. If you want to communicate
with it while its running xml-rpc would probably work nicely
(twisted.web.xmlrpc and see the example in doc/examples/).
More information about the Twisted-Python
mailing list