[Twisted-Python] How do I debug this network problem?

Peter Westlake peter.westlake at pobox.com
Fri Nov 21 07:13:59 MST 2014


On Fri, 21 Nov 2014, at 14:08, Peter Westlake wrote:
> Found it!
>
> from twisted.internet.protocol import ClientFactory, Protocol,
> ProcessProtocol from twisted.internet import reactor
>
> devnull = open('/dev/null').fileno() print devnull
>
> factory = ClientFactory() factory.protocol = Protocol
> reactor.connectTCP('localhost', 'http', factory)
> reactor.callWhenRunning(reactor.spawnProcess, ProcessProtocol(),
> '/bin/sleep', args=['/bin/sleep', '1000'], childFDs={0: devnull, 1:
> 'r', 2:'r'}) reactor.run()
>
> Run this, then:
>
> lsof -I @localhost
>
> will show that the child process has the socket open on FD 0.
>
> Now I grant that there's no need to pass /dev/null to the stdin of the
> process. I should just leave 0 out of childFDs instead. But why does
> this not work? lsof shows that the socket is on FD 3 in the parent
> process, and the print statement shows that the FD of devnull is 3 as
> well! Am I missing something obvious?
>
> Peter.

I *am* missing something obvious. The file opened by open() immediately
goes out of scope. AAAUGH!

Peter.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20141121/d839de62/attachment-0002.html>


More information about the Twisted-Python mailing list