mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Set the FDs non-blocking in the selectors example.
This commit is contained in:
parent
de3a1363a9
commit
a9f90bc602
1 changed files with 12 additions and 9 deletions
|
@ -218,13 +218,16 @@ Examples of selector usage::
|
|||
>>> s = selectors.DefaultSelector()
|
||||
>>> r, w = socket.socketpair()
|
||||
>>>
|
||||
>>> r.setblocking(False)
|
||||
>>> w.setblocking(False)
|
||||
>>>
|
||||
>>> s.register(r, selectors.EVENT_READ)
|
||||
SelectorKey(fileobj=<socket.socket fd=4, family=1, type=1, proto=0>, fd=4, events=1, data=None)
|
||||
SelectorKey(fileobj=<socket.socket fd=4, family=AddressFamily.AF_UNIX, type=2049, proto=0>, fd=4, events=1, data=None)
|
||||
>>> s.register(w, selectors.EVENT_WRITE)
|
||||
SelectorKey(fileobj=<socket.socket fd=5, family=1, type=1, proto=0>, fd=5, events=2, data=None)
|
||||
SelectorKey(fileobj=<socket.socket fd=5, family=AddressFamily.AF_UNIX, type=2049, proto=0>, fd=5, events=2, data=None)
|
||||
>>>
|
||||
>>> print(s.select())
|
||||
[(SelectorKey(fileobj=<socket.socket fd=5, family=1, type=1, proto=0>, fd=5, events=2, data=None), 2)]
|
||||
[(SelectorKey(fileobj=<socket.socket fd=5, family=AddressFamily.AF_UNIX, type=2049, proto=0>, fd=5, events=2, data=None), 2)]
|
||||
>>>
|
||||
>>> for key, events in s.select():
|
||||
... if events & selectors.EVENT_WRITE:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue