On Tue, 10 Mar 2009, Michael Abbott wrote:
> On Tue, 10 Mar 2009, Abbott, MG (Michael) wrote:
> stdin, ... is a device and therefore doesn't work with darwin's
> poll. In this case poll just spews POLLNVAL
> Ok, so poll() on Darwin is busted.
>
> Looks like I'll have to code up an emulation of poll() using select() and
Juan,
Can you try the attached patch and let me know how things behave.
This is a quick and dirty hack, if it's ok I'll work up a proper release.
The problem with using select is that its error handling is lousy: if any
file handle is invalid I have to back out and individually call select()
on each handle, one by one, to find the offending ones.
Regards,
Michael Index: cothread/coselect.py
===================================================================
--- cothread/coselect.py (revision 28616)
+++ cothread/coselect.py (working copy)
@@ -101,6 +101,55 @@
return []
+def poll_block_select(poll_list, timeout = None):
+ '''This reimplements the functionality of poll_block but using select
+ instead. This is intended to be used
+ 1. where poll is not available
+ 2. on OSX where poll is broken, does not work on all file descriptors,
+ in particular not on stdin.
+ '''
+ flag_mapping = (POLLIN, POLLOUT, POLLPRI)
+
+ # Generate list of arguments for select from poll arguments.
+ selects = ([], [], [])
+ for file, events in poll_list:
+ for wtd, event in zip(selects, flag_mapping):
+ if events & event:
+ wtd.append(file)
+
+ result = {}
+ try:
+ selected = _select.select(*selects + (timeout,))
+ except _select.error:
+ # Oh dear. *Something* is wrong, but I don't know which file handle
+ # is broken. This is not good: going to have to probe each file in
+ # turn to find out.
+ for file, events in poll_list:
+ selects = ([], [], [])
+ for wtd, event in zip(selects, flag_mapping):
+ if events & event:
+ wtd.append(file)
+ try:
+ selected = _select.select(*selects + (0,))
+ except _select.error:
+ # Still don't really know what's wrong, but it's a safe bet
+ # the problem is the file handle.
+ result[file] = POLLNVAL
+ else:
+ for wtd, event in zip(selected, flag_mapping):
+ if file in wtd:
+ result[file] = result.get(file, 0) | event
+ else:
+ # Map select result into poll list result.
+ for file, events in poll_list:
+ for wtd, event in zip(selected, flag_mapping):
+ if file in wtd:
+ result[file] = result.get(file, 0) | event
+
+ return result.items()
+
+poll_block = poll_block_select
+
def _compute_poll_list(poll_queue):
'''Computes a list of (file, event_mask) pairs of all descriptor events
of interest, according to the given poll_queue, which is itself a
- Replies:
- Re: Problem with cothread-1-12 on MacOSX (Leopard) Juan Carlos Guzman
- References:
- RE: Problem with cothread-1-12 on MacOSX (Leopard) Abbott, MG (Michael)
- RE: Problem with cothread-1-12 on MacOSX (Leopard) Michael Abbott
- Navigate by Date:
- Prev:
RE: Problem with cothread-1-12 on MacOSX (Leopard) Michael Abbott
- Next:
Re: FW: edm version 1-11-1zl and fedora 10 John Sinclair
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
<2009>
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
RE: Problem with cothread-1-12 on MacOSX (Leopard) Michael Abbott
- Next:
Re: Problem with cothread-1-12 on MacOSX (Leopard) Juan Carlos Guzman
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
<2009>
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|