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
4ed63745
Commit
4ed63745
authored
Feb 12, 2012
by
Ross Lagerwall
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Attempt to speed up some subprocess tests (and hopefully keep them reliable).
parent
ee1e9649
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
24 deletions
+21
-24
Lib/test/test_subprocess.py
Lib/test/test_subprocess.py
+21
-24
No files found.
Lib/test/test_subprocess.py
View file @
4ed63745
...
...
@@ -686,26 +686,19 @@ class ProcessTestCase(BaseTestCase):
self
.
assertEqual
(
subprocess
.
list2cmdline
([
'ab'
,
''
]),
'ab ""'
)
def
test_poll
(
self
):
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
"import time; time.sleep(1)"
])
count
=
0
while
p
.
poll
()
is
None
:
time
.
sleep
(
0.1
)
count
+=
1
# We expect that the poll loop probably went around about 10 times,
# but, based on system scheduling we can't control, it's possible
# poll() never returned None. It "should be" very rare that it
# didn't go around at least twice.
self
.
assertGreaterEqual
(
count
,
2
)
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
"import os"
,
"os.read(1)"
],
stdin
=
subprocess
.
PIPE
)
self
.
addCleanup
(
p
.
stdin
.
close
)
self
.
assertIsNone
(
p
.
poll
())
os
.
write
(
p
.
stdin
.
fileno
(),
b'A'
)
p
.
wait
()
# Subsequent invocations should just return the returncode
self
.
assertEqual
(
p
.
poll
(),
0
)
def
test_wait
(
self
):
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
"import time; time.sleep(2)"
])
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
"pass"
])
self
.
assertEqual
(
p
.
wait
(),
0
)
# Subsequent invocations should just return the returncode
self
.
assertEqual
(
p
.
wait
(),
0
)
...
...
@@ -797,25 +790,29 @@ class ProcessTestCase(BaseTestCase):
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'pass'
],
stdin
=
subprocess
.
PIPE
)
self
.
addCleanup
(
p
.
stdin
.
close
)
time
.
sleep
(
2
)
p
.
wait
(
)
p
.
communicate
(
b"x"
*
2
**
20
)
@
unittest
.
skipUnless
(
hasattr
(
signal
,
'SIGALRM'
),
"Requires signal.SIGALRM"
)
@
unittest
.
skipUnless
(
hasattr
(
signal
,
'SIGUSR1'
),
"Requires signal.SIGUSR1"
)
@
unittest
.
skipUnless
(
hasattr
(
os
,
'kill'
),
"Requires os.kill"
)
@
unittest
.
skipUnless
(
hasattr
(
os
,
'getppid'
),
"Requires os.getppid"
)
def
test_communicate_eintr
(
self
):
# Issue #12493: communicate() should handle EINTR
def
handler
(
signum
,
frame
):
pass
old_handler
=
signal
.
signal
(
signal
.
SIG
ALRM
,
handler
)
self
.
addCleanup
(
signal
.
signal
,
signal
.
SIG
ALRM
,
old_handler
)
old_handler
=
signal
.
signal
(
signal
.
SIG
USR1
,
handler
)
self
.
addCleanup
(
signal
.
signal
,
signal
.
SIG
USR1
,
old_handler
)
# the process is running for 2 seconds
args
=
[
sys
.
executable
,
"-c"
,
'import time; time.sleep(2)'
]
args
=
[
sys
.
executable
,
"-c"
,
'import os, signal;'
'os.kill(os.getppid(), signal.SIGUSR1)'
]
for
stream
in
(
'stdout'
,
'stderr'
):
kw
=
{
stream
:
subprocess
.
PIPE
}
with
subprocess
.
Popen
(
args
,
**
kw
)
as
process
:
signal
.
alarm
(
1
)
# communicate() will be interrupted by SIGALRM
# communicate() will be interrupted by SIGUSR1
process
.
communicate
()
...
...
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