Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
94b56117
Commit
94b56117
authored
Jul 08, 2015
by
Eddi Linder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for a green poll (includes monkey patching)
parent
6fe727c0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
6 deletions
+64
-6
gevent/monkey.py
gevent/monkey.py
+1
-3
gevent/select.py
gevent/select.py
+50
-3
greentest/test__select.py
greentest/test__select.py
+13
-0
No files found.
gevent/monkey.py
View file @
94b56117
...
...
@@ -248,7 +248,6 @@ def patch_select(aggressive=True):
# since these are blocking we're removing them here. This makes some other
# modules (e.g. asyncore) non-blocking, as they use select that we provide
# when none of these are available.
remove_item
(
select
,
'poll'
)
remove_item
(
select
,
'epoll'
)
remove_item
(
select
,
'kqueue'
)
remove_item
(
select
,
'kevent'
)
...
...
@@ -268,9 +267,8 @@ def patch_select(aggressive=True):
if
aggressive
:
# If `selectors` had already been imported before we removed
# select.
poll|
epoll|kqueue, these may have been defined in terms
# select.epoll|kqueue, these may have been defined in terms
# of those functions. They'll fail at runtime.
remove_item
(
selectors
,
'PollSelector'
)
remove_item
(
selectors
,
'EpollSelector'
)
remove_item
(
selectors
,
'KqueueSelector'
)
selectors
.
DefaultSelector
=
selectors
.
SelectSelector
...
...
gevent/select.py
View file @
94b56117
...
...
@@ -3,11 +3,13 @@ from __future__ import absolute_import
from
gevent.event
import
Event
from
gevent.hub
import
get_hub
from
gevent.hub
import
integer_types
from
select
import
POLLIN
,
POLLOUT
__implements__
=
[
'select'
]
__implements__
=
[
'select'
,
'poll'
]
__all__
=
[
'error'
]
+
__implements__
import
select
as
__select__
error
=
__select__
.
error
...
...
@@ -16,14 +18,13 @@ def get_fileno(obj):
fileno_f
=
obj
.
fileno
except
AttributeError
:
if
not
isinstance
(
obj
,
integer_types
):
raise
TypeError
(
'argument must be an int, or have a fileno() method: %r'
%
(
obj
,
))
raise
TypeError
(
'argument must be an int, or have a fileno() method: %r'
%
(
obj
,))
return
obj
else
:
return
fileno_f
()
class
SelectResult
(
object
):
__slots__
=
[
'read'
,
'write'
,
'event'
]
def
__init__
(
self
):
...
...
@@ -69,3 +70,49 @@ def select(rlist, wlist, xlist, timeout=None):
finally
:
for
watcher
in
watchers
:
watcher
.
stop
()
class
PollResult
(
object
):
__slots__
=
[
'events'
,
'event'
]
def
__init__
(
self
):
self
.
events
=
[]
self
.
event
=
Event
()
def
add_event
(
self
,
events
,
fd
):
result_flags
=
0
result_flags
|=
POLLIN
if
events
&
1
else
0
result_flags
|=
POLLOUT
if
events
&
2
else
0
self
.
events
.
append
((
fd
,
result_flags
))
self
.
event
.
set
()
class
poll
(
object
):
def
__init__
(
self
):
self
.
fds
=
{}
self
.
loop
=
get_hub
().
loop
def
register
(
self
,
fd
,
eventmask
=
POLLIN
|
POLLOUT
):
flags
=
0
flags
|=
1
if
eventmask
&
POLLIN
else
0
flags
|=
2
if
eventmask
&
POLLOUT
else
0
watcher
=
self
.
loop
.
io
(
get_fileno
(
fd
),
flags
)
watcher
.
priority
=
self
.
loop
.
MAXPRI
self
.
fds
[
fd
]
=
watcher
def
modify
(
self
,
fd
,
eventmask
):
self
.
register
(
fd
,
eventmask
)
def
poll
(
self
,
timeout
=
None
):
result
=
PollResult
()
try
:
for
fd
in
self
.
fds
:
self
.
fds
[
fd
].
start
(
result
.
add_event
,
get_fileno
(
fd
),
pass_events
=
True
)
result
.
event
.
wait
(
timeout
=
timeout
)
return
result
.
events
finally
:
for
fd
in
self
.
fds
:
self
.
fds
[
fd
].
stop
()
def
unregister
(
self
,
fd
):
self
.
fds
.
pop
(
fd
,
None
)
greentest/test__select.py
View file @
94b56117
...
...
@@ -24,6 +24,19 @@ if sys.platform != 'win32':
os
.
close
(
w
)
class
TestPollRead
(
greentest
.
GenericWaitTestCase
):
def
wait
(
self
,
timeout
):
r
,
w
=
os
.
pipe
()
try
:
poll
=
select
.
poll
()
poll
.
register
(
r
)
poll
.
poll
(
timeout
)
poll
.
unregister
(
r
)
finally
:
os
.
close
(
r
)
os
.
close
(
w
)
class
TestSelectTypes
(
greentest
.
TestCase
):
def
test_int
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment