[Twisted-Python] Problem w/ TNPE Example on Windows
![](https://secure.gravatar.com/avatar/047cc6370137b7cd7adef5787d3ff24e.jpg?s=120&d=mm&r=g)
Hello, I'm new to Twisted and just started reading "Twisted Network Programming Essentials". The example "dataforward.py" in chapter 2 creates a traceback and an import error, if executed on my laptop running WinXP/Pro-SP2, using Python-2.4.2 and Twisted-2.1.0 The import error complains about a missing module "fcntl" required by ...\twisted\internet\fdesc.py Reading the python documentation states that the "fcntl" module is available on Unix only. - Does that mean, that this example is working on Unix only or what am I missing? Kind regards, Viktor Ransmayr
![](https://secure.gravatar.com/avatar/b3407ff6ccd34c6e7c7a9fdcfba67a45.jpg?s=120&d=mm&r=g)
On Sun, Dec 18, 2005 at 10:29:50PM +0100, Viktor Ransmayr wrote:
Hello,
I'm new to Twisted and just started reading "Twisted Network Programming Essentials".
The example "dataforward.py" in chapter 2 creates a traceback and an import error, if executed on my laptop running WinXP/Pro-SP2, using Python-2.4.2 and Twisted-2.1.0
The import error complains about a missing module "fcntl" required by ...\twisted\internet\fdesc.py
Reading the python documentation states that the "fcntl" module is available on Unix only. - Does that mean, that this example is working on Unix only or what am I missing?
That's right, unfortunately. That example uses the twisted.internet.stdio module, which relies on fcntl (and the ability to pass the stdin/stdout file descriptors to select), which isn't available on Windows. -Andrew.
![](https://secure.gravatar.com/avatar/6cd37343ce1da139b1d2ff5ee717f5d5.jpg?s=120&d=mm&r=g)
Andrew Bennetts wrote:
Reading the python documentation states that the "fcntl" module is available on Unix only. - Does that mean, that this example is working on Unix only or what am I missing?
That's right, unfortunately. That example uses the twisted.internet.stdio module, which relies on fcntl (and the ability to pass the stdin/stdout file descriptors to select), which isn't available on Windows.
And unfortunately I failed to notice this while writing the book. Apologies to Windows users. Is it really impossible to do asynchronous IO on stdin/out on Windows? Anybody have any ideas for working around the lack of fcntl? I'd be happy to contribute to an effort to make twisted.internet.stdio run on Windows. Abe
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
On Mon, 2005-12-19 at 11:23 -0500, Abe Fettig wrote:
And unfortunately I failed to notice this while writing the book. Apologies to Windows users. Is it really impossible to do asynchronous IO on stdin/out on Windows? Anybody have any ideas for working around the lack of fcntl? I'd be happy to contribute to an effort to make twisted.internet.stdio run on Windows.
*mumble* *mumble* *blush*. That's my fault, since I did know that. It may be possible to do stdio on Windows using the IOCP reactor.
![](https://secure.gravatar.com/avatar/f23431e20ecae7b406698c1bb950b80f.jpg?s=120&d=mm&r=g)
Itamar Shtull-Trauring a écrit :
On Mon, 2005-12-19 at 11:23 -0500, Abe Fettig wrote:
And unfortunately I failed to notice this while writing the book. Apologies to Windows users. Is it really impossible to do asynchronous IO on stdin/out on Windows? Anybody have any ideas for working around the lack of fcntl? I'd be happy to contribute to an effort to make twisted.internet.stdio run on Windows.
*mumble* *mumble* *blush*. That's my fault, since I did know that.
It may be possible to do stdio on Windows using the IOCP reactor.
Talking about that, what is the exact status of the IOCP reactor? I have seen J. Johnson commiting patches related to process creation recently. Are there still mandatory features missing to have complete reactor? Patrick Mézard
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
On Mon, 2005-12-19 at 21:06 +0100, Patrick Mézard wrote:
Talking about that, what is the exact status of the IOCP reactor? I have seen J. Johnson commiting patches related to process creation recently. Are there still mandatory features missing to have complete reactor?
At the minimum, producer/consumer API and passing tests; TLS/SSL support would also be a very useful addition however.
![](https://secure.gravatar.com/avatar/6cd37343ce1da139b1d2ff5ee717f5d5.jpg?s=120&d=mm&r=g)
Itamar Shtull-Trauring wrote:
On Mon, 2005-12-19 at 11:23 -0500, Abe Fettig wrote:
And unfortunately I failed to notice this while writing the book. Apologies to Windows users. Is it really impossible to do asynchronous IO on stdin/out on Windows? Anybody have any ideas for working around the lack of fcntl? I'd be happy to contribute to an effort to make twisted.internet.stdio run on Windows.
*mumble* *mumble* *blush*. That's my fault, since I did know that.
No, it's my fault. Don't worry about it. The buck stops here. You can make it up to me by helping make twisted.internet.stdio work on Windows though :-)
It may be possible to do stdio on Windows using the IOCP reactor.
According to the inline docs, twisted.internet.stdio is: unstable (pending deprecation in favor of a reactor-based API) Future Plans: support for stderr, perhaps Rewrite to use the reactor instead of an ad-hoc mechanism for connecting protocols to transport. So for now, stdio in Twisted isn't reactor specific. As we're discussing here, though, it only works on Unixy operating systems. Would it be sane to try and import the fcntl module, and if that fails fall back to using threads to fake async stdio? Abe
![](https://secure.gravatar.com/avatar/15fa47f2847592672210af8a25cd1f34.jpg?s=120&d=mm&r=g)
On Dec 19, 2005, at 11:23 AM, Abe Fettig wrote:
Andrew Bennetts wrote:
Reading the python documentation states that the "fcntl" module is available on Unix only. - Does that mean, that this example is working on Unix only or what am I missing?
That's right, unfortunately. That example uses the twisted.internet.stdio module, which relies on fcntl (and the ability to pass the stdin/ stdout file descriptors to select), which isn't available on Windows.
And unfortunately I failed to notice this while writing the book. Apologies to Windows users. Is it really impossible to do asynchronous IO on stdin/out on Windows? Anybody have any ideas for working around the lack of fcntl? I'd be happy to contribute to an effort to make twisted.internet.stdio run on Windows.
In the worst case, it could be emulated using threads doing blocking read/write. James
![](https://secure.gravatar.com/avatar/b3407ff6ccd34c6e7c7a9fdcfba67a45.jpg?s=120&d=mm&r=g)
On Mon, Dec 19, 2005 at 01:19:34PM -0500, James Y Knight wrote:
On Dec 19, 2005, at 11:23 AM, Abe Fettig wrote: [...]
And unfortunately I failed to notice this while writing the book. Apologies to Windows users. Is it really impossible to do asynchronous IO on stdin/out on Windows? Anybody have any ideas for working around the lack of fcntl? I'd be happy to contribute to an effort to make twisted.internet.stdio run on Windows.
In the worst case, it could be emulated using threads doing blocking read/write.
I think this is the simplest and most practical way to implement it on windows. I suggest anyone interested in implementing it on windows tries this method. -Andrew.
participants (6)
-
Abe Fettig
-
Andrew Bennetts
-
Itamar Shtull-Trauring
-
James Y Knight
-
Patrick Mézard
-
Viktor Ransmayr