This post originated from an RSS feed registered with Python Buzz
by Phillip Pearson.
Original Post: Invoking qmail-inject from Python on FreeBSD without hanging
Feed Title: Second p0st
Feed URL: http://www.myelin.co.nz/post/rss.xml
Feed Description: Tech notes and web hackery from the guy that brought you bzero, Python Community Server, the Blogging Ecosystem and the Internet Topic Exchange
I recently ran into some odd behaviour when trying to call qmail's qmail-inject tool from a Python script with os.popen. The script was hanging when I tried to close the file.
It turns out that this is an old bug that is apparently qmail's problem. That doesn't help me, but the workaround in this message does: use popen2.popen2 instead.
Practically, that means that instead of this:
f = os.popen('/var/qmail/bin/qmail-inject %s' % address, 'w')
You want to say:
f = popen2.popen2('/var/qmail/bin/qmail-inject %s' % address)[1]
... and your script will then run fine.
My application was the e-mail responder script that I use to edit Crash. Previously I was just getting the script to time out like this:
I've left that bit in - it serves to kill the script when weblogs.com stops responding. But now, at least, I don't always get a failure response 60 seconds after the success response.