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
b15e622b
Commit
b15e622b
authored
Jul 27, 2012
by
Richard Oudkerk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #6056: Make multiprocessing use setblocking(True) on the sockets it uses.
Original patch by J Derek Wilson.
parent
46874ad3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
1 deletion
+44
-1
Lib/multiprocessing/connection.py
Lib/multiprocessing/connection.py
+5
-0
Lib/test/test_multiprocessing.py
Lib/test/test_multiprocessing.py
+35
-1
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/multiprocessing/connection.py
View file @
b15e622b
...
...
@@ -497,6 +497,8 @@ if sys.platform != 'win32':
'''
if
duplex
:
s1
,
s2
=
socket
.
socketpair
()
s1
.
setblocking
(
True
)
s2
.
setblocking
(
True
)
c1
=
Connection
(
s1
.
detach
())
c2
=
Connection
(
s2
.
detach
())
else
:
...
...
@@ -561,6 +563,7 @@ class SocketListener(object):
if
os
.
name
==
'posix'
:
self
.
_socket
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
self
.
_socket
.
setblocking
(
True
)
self
.
_socket
.
bind
(
address
)
self
.
_socket
.
listen
(
backlog
)
self
.
_address
=
self
.
_socket
.
getsockname
()
...
...
@@ -579,6 +582,7 @@ class SocketListener(object):
def
accept
(
self
):
s
,
self
.
_last_accepted
=
self
.
_socket
.
accept
()
s
.
setblocking
(
True
)
return
Connection
(
s
.
detach
())
def
close
(
self
):
...
...
@@ -593,6 +597,7 @@ def SocketClient(address):
'''
family
=
address_type
(
address
)
with
socket
.
socket
(
getattr
(
socket
,
family
)
)
as
s
:
s
.
setblocking
(
True
)
s
.
connect
(
address
)
return
Connection
(
s
.
detach
())
...
...
Lib/test/test_multiprocessing.py
View file @
b15e622b
...
...
@@ -3312,9 +3312,43 @@ class TestFlags(unittest.TestCase):
child_flags
,
grandchild_flags
=
json
.
loads
(
data
.
decode
(
'ascii'
))
self
.
assertEqual
(
child_flags
,
grandchild_flags
)
#
# Test interaction with socket timeouts - see Issue #6056
#
class
TestTimeouts
(
unittest
.
TestCase
):
@
classmethod
def
_test_timeout
(
cls
,
child
,
address
):
time
.
sleep
(
1
)
child
.
send
(
123
)
child
.
close
()
conn
=
multiprocessing
.
connection
.
Client
(
address
)
conn
.
send
(
456
)
conn
.
close
()
def
test_timeout
(
self
):
old_timeout
=
socket
.
getdefaulttimeout
()
try
:
socket
.
setdefaulttimeout
(
0.1
)
parent
,
child
=
multiprocessing
.
Pipe
(
duplex
=
True
)
l
=
multiprocessing
.
connection
.
Listener
(
family
=
'AF_INET'
)
p
=
multiprocessing
.
Process
(
target
=
self
.
_test_timeout
,
args
=
(
child
,
l
.
address
))
p
.
start
()
child
.
close
()
self
.
assertEqual
(
parent
.
recv
(),
123
)
parent
.
close
()
conn
=
l
.
accept
()
self
.
assertEqual
(
conn
.
recv
(),
456
)
conn
.
close
()
l
.
close
()
p
.
join
(
10
)
finally
:
socket
.
setdefaulttimeout
(
old_timeout
)
testcases_other
=
[
OtherTest
,
TestInvalidHandle
,
TestInitializers
,
TestStdinBadfiledescriptor
,
TestWait
,
TestInvalidFamily
,
TestFlags
]
TestFlags
,
TestTimeouts
]
#
#
...
...
Misc/ACKS
View file @
b15e622b
...
...
@@ -1130,6 +1130,7 @@ John Williams
Sue Williams
Frank Willison
Greg V. Wilson
J Derek Wilson
Jody Winston
Collin Winter
Dik Winter
...
...
Misc/NEWS
View file @
b15e622b
...
...
@@ -55,6 +55,9 @@ Core and Builtins
Library
-------
-
Issue
#
6056
:
Make
multiprocessing
use
setblocking
(
True
)
on
the
sockets
it
uses
.
Original
patch
by
J
Derek
Wilson
.
-
Issue
#
15364
:
Fix
sysconfig
.
get_config_var
(
'srcdir'
)
to
be
an
absolute
path
.
...
...
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