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

Glyph glyph at twistedmatrix.com
Fri Nov 21 19:58:09 MST 2014


> On Nov 22, 2014, at 01:50, Peter Westlake <peter.westlake at pobox.com> wrote:
> 
> On Fri, 21 Nov 2014, at 19:26, Glyph wrote:
>>> On Nov 21, 2014, at 15:13, Peter Westlake <peter.westlake at pobox.com <mailto:peter.westlake at pobox.com>> wrote:
>>>  
>>> Iammissing something obvious. The file opened by open() immediately goes out of scope.  AAAUGH!
>> 
>>  
>> So... back to square one?  Or is this the solution to your problem?  I don't entirely follow how this connects..
>  
> I didn't explain, sorry. This does indeed solve my problem!

Thanks for explaining that whole interaction.  Wow, that is a scary amount of abstraction-boundary-crossing, congratulations on diagnosing it :-).

> To fix the bug (and it is fixed, and passes testing) I had the option of either saving the file object:
>  
> devnull = open('/dev/null')
> ...
> spawnProcess(...childFDS{0: devnull.fileno(), 1: 'r', 2: 'r'}...)
>  
> or closing stdin:
>  
> spawnProcess(...childFDS{1: 'r', 2: 'r'}...)

Closing stdin is probably the best option here, but the original problem was caused by a mixing of levels.

On one level, you've got open(), which wants to sort of pretend that an open file is an object, and that the operating system resource involved is an implementation detail that can be cleaned up by the garbage collector.

On the other level, you've got spawnProcess, which is operating entirely in terms of file descriptors as process-global state.

Any time you want to open a file descriptor for spawnProcess to consume, I suggest that you open it with os.open <https://docs.python.org/2/library/os.html#os.open <https://docs.python.org/2/library/os.html#os.open>>, which just hands you an integer and makes it your own problem to close it explicitly with os.close <https://docs.python.org/2/library/os.html#os.close <https://docs.python.org/2/library/os.html#os.close>>; this is operating at the same abstraction level and therefore less error-prone.

-glyph



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


More information about the Twisted-Python mailing list