[Twisted-Python] buildProtocol never called

travis+ml-twisted at subspacefield.org travis+ml-twisted at subspacefield.org
Sat May 30 17:36:16 MDT 2009


On Sat, May 30, 2009 at 06:17:54PM -0500, travis+ml-twisted at subspacefield.org wrote:
> The program works fine normally, and can run in the background, but if I
> invoke a daemonize() routine that turns it into a network daemon, it
> refuses to serve incoming TCP connections.  Actually the TCP connection
> is made, but the software never responds to it.
> 
> Specifically, my twisted.internet.protocol.Factory instance is created,
> but buildProtocol is never called.
> 
> Before I dive deeply into debugging the software, I thought I'd ask if
> anyone knew off the top of their head any reason why Twisted might not
> act the same if it was daemonized (no controlling terminal, no
> stdin/out/err, forked as a background process).

Here's some behavior I've gathered through debugging.  Note that all of
the daemonization occurs before starting the reactor.

If I don't close any file descriptors during daemonization, the
program works fine.

If I close all file descriptors (3, 4, 5, 6, 7)  and above, it works, but upon
disconnecting, I get the following error message:

  File "/etc/keeper_screen", line 675, in <module>
    reactor.run()
  File "/usr/local/lib/python2.5/site-packages/twisted/internet/base.py", line 1128, in run
    self.mainLoop()
--- <exception caught here> ---
  File "/usr/local/lib/python2.5/site-packages/twisted/internet/base.py", line 1140, in mainLoop
    self.doIteration(t)
  File "/usr/local/lib/python2.5/site-packages/twisted/internet/selectreactor.py", line 126, in doSelect
    self._preenDescriptors()
  File "/usr/local/lib/python2.5/site-packages/twisted/internet/selectreactor.py", line 88, in _preenDescriptors
    self._disconnectSelectable(selectable, e, False)
  File "/usr/local/lib/python2.5/site-packages/twisted/internet/posixbase.py", line 196, in _disconnectSelectable
    selectable.connectionLost(failure.Failure(why))
  File "/usr/local/lib/python2.5/site-packages/twisted/internet/posixbase.py", line 150, in connectionLost
    os.close(fd)
exceptions.OSError: [Errno 9] Bad file descriptor

If I close all file descriptors two and above, I get that error message immediately.

If I close all file descriptors eight and above, the program works normally.

Is there some code in Twisted that expects certain file descriptors to be open?

Anyone got a clue what could be happening here?
-- 
Obama Nation | My emails do not have attachments; it's a digital signature
that your mail program doesn't understand. | http://www.subspacefield.org/~travis/ 
If you are a spammer, please email john at subspacefield.org to get blacklisted.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20090530/2c7177f4/attachment.sig>


More information about the Twisted-Python mailing list