Skip to content

Commit 96164f8

Browse files
committed
Make the select call in item 37 work on Windows
1 parent 4a0a3b6 commit 96164f8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

example_code/item_37.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,15 @@ def run(self):
6767

6868
# Example 6
6969
import select
70+
import socket
71+
72+
# This is for supporting Windows specifically. Windows can't do a
73+
# select call with an empty list. Don't connect the socket to anything.
74+
# Waiting for it will do nothing.
75+
_s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7076

7177
def slow_systemcall():
72-
select.select([], [], [], 0.1)
78+
select.select([_s], [], [], 0.1)
7379

7480

7581
# Example 7

0 commit comments

Comments
 (0)