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
5617df1b
Commit
5617df1b
authored
Aug 20, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #8865: Concurrent invocation of select.poll.poll() now raises a
RuntimeError exception. Patch by Christian Schubert.
parents
edd0de58
b1973c25
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
2 deletions
+57
-2
Lib/test/test_poll.py
Lib/test/test_poll.py
+40
-2
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/selectmodule.c
Modules/selectmodule.c
+13
-0
No files found.
Lib/test/test_poll.py
View file @
5617df1b
# Test case for the os.poll() function
import
os
,
select
,
random
,
unittest
,
subprocess
import
os
import
random
import
select
import
_testcapi
from
test.support
import
TESTFN
,
run_unittest
try
:
import
threading
except
ImportError
:
threading
=
None
import
time
import
unittest
from
test.support
import
TESTFN
,
run_unittest
,
reap_threads
try
:
select
.
poll
...
...
@@ -161,6 +169,36 @@ class PollTests(unittest.TestCase):
self
.
assertRaises
(
OverflowError
,
pollster
.
poll
,
_testcapi
.
INT_MAX
+
1
)
self
.
assertRaises
(
OverflowError
,
pollster
.
poll
,
_testcapi
.
UINT_MAX
+
1
)
@
unittest
.
skipUnless
(
threading
,
'Threading required for this test.'
)
@
reap_threads
def
test_threaded_poll
(
self
):
r
,
w
=
os
.
pipe
()
self
.
addCleanup
(
os
.
close
,
r
)
self
.
addCleanup
(
os
.
close
,
w
)
rfds
=
[]
for
i
in
range
(
10
):
fd
=
os
.
dup
(
r
)
self
.
addCleanup
(
os
.
close
,
fd
)
rfds
.
append
(
fd
)
pollster
=
select
.
poll
()
for
fd
in
rfds
:
pollster
.
register
(
fd
,
select
.
POLLIN
)
t
=
threading
.
Thread
(
target
=
pollster
.
poll
)
t
.
start
()
try
:
time
.
sleep
(
0.5
)
# trigger ufds array reallocation
for
fd
in
rfds
:
pollster
.
unregister
(
fd
)
pollster
.
register
(
w
,
select
.
POLLOUT
)
self
.
assertRaises
(
RuntimeError
,
pollster
.
poll
)
finally
:
# and make the call to poll() from the thread return
os
.
write
(
w
,
b'spam'
)
t
.
join
()
def
test_main
():
run_unittest
(
PollTests
)
...
...
Misc/ACKS
View file @
5617df1b
...
...
@@ -1131,6 +1131,7 @@ Arvin Schnell
Scott Schram
Robin Schreiber
Chad J. Schroeder
Christian Schubert
Sam Schulenburg
Stefan Schwarzer
Dietmar Schwertberger
...
...
Misc/NEWS
View file @
5617df1b
...
...
@@ -38,6 +38,9 @@ Core and Builtins
Library
-------
- Issue #8865: Concurrent invocation of select.poll.poll() now raises a
RuntimeError exception. Patch by Christian Schubert.
- Issue #18777: The ssl module now uses the new CRYPTO_THREADID API of
OpenSSL 1.0.0+ instead of the deprecated CRYPTO id callback function.
...
...
Modules/selectmodule.c
View file @
5617df1b
...
...
@@ -327,6 +327,7 @@ typedef struct {
int
ufd_uptodate
;
int
ufd_len
;
struct
pollfd
*
ufds
;
int
poll_running
;
}
pollObject
;
static
PyTypeObject
poll_Type
;
...
...
@@ -523,16 +524,27 @@ poll_poll(pollObject *self, PyObject *args)
return
NULL
;
}
/* Avoid concurrent poll() invocation, issue 8865 */
if
(
self
->
poll_running
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
"concurrent poll() invocation"
);
return
NULL
;
}
/* Ensure the ufd array is up to date */
if
(
!
self
->
ufd_uptodate
)
if
(
update_ufd_array
(
self
)
==
0
)
return
NULL
;
self
->
poll_running
=
1
;
/* call poll() */
Py_BEGIN_ALLOW_THREADS
poll_result
=
poll
(
self
->
ufds
,
self
->
ufd_len
,
timeout
);
Py_END_ALLOW_THREADS
self
->
poll_running
=
0
;
if
(
poll_result
<
0
)
{
PyErr_SetFromErrno
(
PyExc_OSError
);
return
NULL
;
...
...
@@ -609,6 +621,7 @@ newPollObject(void)
array pointed to by ufds matches the contents of the dictionary. */
self
->
ufd_uptodate
=
0
;
self
->
ufds
=
NULL
;
self
->
poll_running
=
0
;
self
->
dict
=
PyDict_New
();
if
(
self
->
dict
==
NULL
)
{
Py_DECREF
(
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