Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a9f90bc6
Commit
a9f90bc6
authored
Nov 29, 2013
by
Charles-François Natali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set the FDs non-blocking in the selectors example.
parent
de3a1363
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
9 deletions
+12
-9
Doc/library/selectors.rst
Doc/library/selectors.rst
+12
-9
No files found.
Doc/library/selectors.rst
View file @
a9f90bc6
...
...
@@ -214,26 +214,29 @@ Examples of selector usage::
>>> import selectors
>>> import socket
>>>
>>>
>>> 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:
... key.fileobj.send(b'spam')
...
...
4
>>> for key, events in s.select():
... if events & selectors.EVENT_READ:
... print(key.fileobj.recv(1024))
...
...
b'spam'
>>> s.close()
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