[Twisted-Python] You guys rock
![](https://secure.gravatar.com/avatar/a930430c7f9705b71a65f341c4191a2b.jpg?s=120&d=mm&r=g)
I wanted to test out some news/mail gatewaying for Mailman 2.1 but I didn't want to go through the hassle of actually connecting things up to a real news server, and I /definitely/ didn't want to actually try to install inn or some nonesense (I'd like to do some other work this week :). I wished I had something like Lib/smtpd.py in the Python distro for the server side of NNTP, then it dawned on me that I remember Moshe and crew saying that Twisted comes with a news server. Well, let's just see how easy it would be to hook up. You guys have a big problem, because it was /way/ too easy to do! How are you going to make the big consulting bucks? :) 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! 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? I'm not on this list so please CC me. Anyway, good stuff, thanks. -Barry P.S. You guys need a bass player. :)
![](https://secure.gravatar.com/avatar/433365de0f787faa3ed3e6dd1da5884f.jpg?s=120&d=mm&r=g)
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!
Thanks - can we ask you for a quote for our 1.0 press release?
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/).
![](https://secure.gravatar.com/avatar/433365de0f787faa3ed3e6dd1da5884f.jpg?s=120&d=mm&r=g)
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!
Thanks - can we ask you for a quote for our 1.0 press release?
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/).
participants (2)
-
barry@zope.com
-
Itamar Shtull-Trauring