[Twisted-Python] No-op TimerService on Windows?

Hi, In the process of exploring my options for deploying twisted applications on Windows, I noticed that when running the application, _twistw (line 43) also starts a TimerService around a no-op: app.startApplication(internet.TimerService(0.1, lambda:None), 0) I suppose there is very good reason to do so, but I do not see it. Can somebody enlighten me? Eric.

On Thu, 4 May 2006 11:05:21 +0200, Eric Faurot <eric.faurot@gmail.com> wrote:
In the process of exploring my options for deploying twisted applications on Windows, I noticed that when running the application, _twistw (line 43) also starts a TimerService around a no-op:
app.startApplication(internet.TimerService(0.1, lambda:None), 0)
I suppose there is very good reason to do so, but I do not see it. Can somebody enlighten me?
There should be a comment or something to this effect, but: On Windows, the "signal" handling that Control-c triggers doesn't actually interrupt select(). That timer is there to keep the timeout low so that the server responds in a timely fashion when the user hits Control-c on the console, even if nothing else is happening.

On 5/4/06, glyph@divmod.com <glyph@divmod.com> wrote:
On Thu, 4 May 2006 11:05:21 +0200, Eric Faurot <eric.faurot@gmail.com> wrote:
In the process of exploring my options for deploying twisted applications on Windows, I noticed that when running the application, _twistw (line 43) also starts a TimerService around a no-op:
app.startApplication(internet.TimerService(0.1, lambda:None), 0)
I suppose there is very good reason to do so, but I do not see it. Can somebody enlighten me?
There should be a comment or something to this effect, but:
On Windows, the "signal" handling that Control-c triggers doesn't actually interrupt select(). That timer is there to keep the timeout low so that the server responds in a timely fashion when the user hits Control-c on the console, even if nothing else is happening.
Ok, but as far as I can see, it is redundant with way select is wrapped on win32 (in selectreactor). BTW, I am not windows-savvy, but are the arguments to select (r,w,w) really correct? not (r,w,e)? def win32select(r, w, e, timeout=None): """Win32 select wrapper.""" if not (r or w): # windows select() exits immediately when no sockets if timeout is None: timeout = 0.01 else: timeout = min(timeout, 0.001) sleep(timeout) return [], [], [] # windows doesn't process 'signals' inside select(), so we set a max # time or ctrl-c will never be recognized if timeout is None or timeout > 0.5: timeout = 0.5 r, w, e = select.select(r, w, w, timeout) return r, w + e, [] Eric.

On Thu, May 04, 2006 at 05:39:22PM +0200, Eric Faurot wrote:
On 5/4/06, glyph@divmod.com <glyph@divmod.com> wrote:
[...]
There should be a comment or something to this effect, but:
On Windows, the "signal" handling that Control-c triggers doesn't actually interrupt select(). That timer is there to keep the timeout low so that the server responds in a timely fashion when the user hits Control-c on the console, even if nothing else is happening.
Ok, but as far as I can see, it is redundant with way select is wrapped on win32 (in selectreactor). BTW, I am not windows-savvy, but are the arguments to select (r,w,w) really correct? not (r,w,e)?
You're right, this does seem to take care of that problem. I'm not sure what benefit the extra code to do this in twistw adds. As far as (r,w,w) goes, yes, it is correct -- again, there ought to be a comment about this. select on windows is subtly incompatible with select on POSIX, and uses the third fd set to check for connection failures and the like, whereas on POSIX this is just signalled on the first or second fd set. I forget the precise details, but luckily Itamar has recorded them here: http://itamarst.org/writings/win32sockets.html So our win32select wrapper passes the write list as the exception list too, then returns (r, w + e, []) -- so the wrapper behaves more like POSIX, as the SelectReactor expects. -Andrew.
participants (3)
-
Andrew Bennetts
-
Eric Faurot
-
glyph@divmod.com