Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4886d24

Browse files
committed
Merged revisions 78736,78759,78761,78767,78788-78789 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r78736 | florent.xicluna | 2010-03-06 20:43:41 +0100 (sam, 06 mar 2010) | 2 lines Skip test_send_signal, test_kill, test_terminate on win32 platforms, for 2.7a4 release. ........ r78759 | florent.xicluna | 2010-03-07 13:21:36 +0100 (dim, 07 mar 2010) | 2 lines #2777: Enable test_send_signal, test_terminate and test_kill on win32 platforms. ........ r78761 | florent.xicluna | 2010-03-07 16:27:39 +0100 (dim, 07 mar 2010) | 4 lines Do not fail if returncode is 0 on send_signal/kill/terminate, for win32 platforms. Do not hide the KeyboardInterrupt on POSIX platforms. ........ r78767 | florent.xicluna | 2010-03-07 18:12:23 +0100 (dim, 07 mar 2010) | 2 lines #2777: Try hard to make Win7 buildbot happy... ........ r78788 | florent.xicluna | 2010-03-08 11:58:12 +0100 (lun, 08 mar 2010) | 2 lines Fix syntax: "rc != None" -> "rc is not None" ........ r78789 | florent.xicluna | 2010-03-08 11:59:33 +0100 (lun, 08 mar 2010) | 2 lines Replace the stderr logging with assertNotEqual(returncode, 0). ........
1 parent 81c867c commit 4886d24

3 files changed

Lines changed: 46 additions & 39 deletions

File tree

Doc/library/subprocess.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ Return code handling translates as follows::
534534
pipe = os.popen(cmd, 'w')
535535
...
536536
rc = pipe.close()
537-
if rc != None and rc % 256:
537+
if rc is not None and rc % 256:
538538
print("There were some errors")
539539
==>
540540
process = Popen(cmd, 'w', stdin=PIPE)

Lib/subprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class Popen(args, bufsize=0, executable=None,
110110
111111
The arguments are the same as for the Popen constructor. Example:
112112
113-
>>> retcode = call(["ls", "-l"])
113+
>>> retcode = subprocess.call(["ls", "-l"])
114114
115115
check_call(*popenargs, **kwargs):
116116
Run command with arguments. Wait for command to complete. If the
@@ -120,7 +120,7 @@ class Popen(args, bufsize=0, executable=None,
120120
121121
The arguments are the same as for the Popen constructor. Example:
122122
123-
>>> check_call(["ls", "-l"])
123+
>>> subprocess.check_call(["ls", "-l"])
124124
0
125125
126126
getstatusoutput(cmd):

Lib/test/test_subprocess.py

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -648,42 +648,39 @@ def test_call_string(self):
648648
os.remove(fname)
649649
self.assertEqual(rc, 47)
650650

651-
def test_send_signal(self):
651+
def _kill_process(self, method, *args):
652652
# Do not inherit file handles from the parent.
653653
# It should fix failures on some platforms.
654654
p = subprocess.Popen([sys.executable, "-c", "input()"], close_fds=True,
655-
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
655+
stdin=subprocess.PIPE)
656656

657-
# Let the process initialize correctly (Issue #3137)
657+
# Let the process initialize (Issue #3137)
658658
time.sleep(0.1)
659+
# The process should not terminate prematurely
659660
self.assertIsNone(p.poll())
661+
# Retry if the process do not receive the signal.
660662
count, maxcount = 0, 3
661-
# Retry if the process do not receive the SIGINT signal.
662663
while count < maxcount and p.poll() is None:
663-
p.send_signal(signal.SIGINT)
664+
getattr(p, method)(*args)
664665
time.sleep(0.1)
665666
count += 1
666-
self.assertIsNotNone(p.poll(), "the subprocess did not receive "
667-
"the signal SIGINT")
667+
668+
self.assertIsNotNone(p.poll(), "the subprocess did not terminate")
668669
if count > 1:
669-
print("p.send_signal(SIGINT) succeeded "
670-
"after {} attempts".format(count), file=sys.stderr)
670+
print("p.{}{} succeeded after "
671+
"{} attempts".format(method, args, count), file=sys.stderr)
672+
return p
673+
674+
def test_send_signal(self):
675+
p = self._kill_process('send_signal', signal.SIGINT)
671676
self.assertNotEqual(p.wait(), 0)
672677

673678
def test_kill(self):
674-
p = subprocess.Popen([sys.executable, "-c", "input()"],
675-
stdin=subprocess.PIPE, close_fds=True)
676-
677-
self.assertIsNone(p.poll())
678-
p.kill()
679+
p = self._kill_process('kill')
679680
self.assertEqual(p.wait(), -signal.SIGKILL)
680681

681682
def test_terminate(self):
682-
p = subprocess.Popen([sys.executable, "-c", "input()"],
683-
stdin=subprocess.PIPE, close_fds=True)
684-
685-
self.assertIsNone(p.poll())
686-
p.terminate()
683+
p = self._kill_process('terminate')
687684
self.assertEqual(p.wait(), -signal.SIGTERM)
688685

689686

@@ -766,28 +763,38 @@ def test_call_string(self):
766763
' -c "import sys; sys.exit(47)"')
767764
self.assertEqual(rc, 47)
768765

769-
def test_send_signal(self):
770-
# Do not inherit file handles from the parent.
771-
# It should fix failure on some platforms.
772-
p = subprocess.Popen([sys.executable, "-c", "input()"], close_fds=True)
766+
def _kill_process(self, method, *args):
767+
# Some win32 buildbot raises EOFError if stdin is inherited
768+
p = subprocess.Popen([sys.executable, "-c", "input()"],
769+
stdin=subprocess.PIPE)
773770

774-
self.assertIs(p.poll(), None)
775-
p.send_signal(signal.SIGTERM)
776-
self.assertNotEqual(p.wait(), 0)
771+
# Let the process initialize (Issue #3137)
772+
time.sleep(0.1)
773+
# The process should not terminate prematurely
774+
self.assertIsNone(p.poll())
775+
# Retry if the process do not receive the signal.
776+
count, maxcount = 0, 3
777+
while count < maxcount and p.poll() is None:
778+
getattr(p, method)(*args)
779+
time.sleep(0.1)
780+
count += 1
777781

778-
def test_kill(self):
779-
p = subprocess.Popen([sys.executable, "-c", "input()"], close_fds=True)
782+
returncode = p.poll()
783+
self.assertIsNotNone(returncode, "the subprocess did not terminate")
784+
if count > 1:
785+
print("p.{}{} succeeded after "
786+
"{} attempts".format(method, args, count), file=sys.stderr)
787+
self.assertEqual(p.wait(), returncode)
788+
self.assertNotEqual(returncode, 0)
780789

781-
self.assertIs(p.poll(), None)
782-
p.kill()
783-
self.assertNotEqual(p.wait(), 0)
790+
def test_send_signal(self):
791+
self._kill_process('send_signal', signal.SIGTERM)
784792

785-
def test_terminate(self):
786-
p = subprocess.Popen([sys.executable, "-c", "input()"], close_fds=True)
793+
def test_kill(self):
794+
self._kill_process('kill')
787795

788-
self.assertIs(p.poll(), None)
789-
p.terminate()
790-
self.assertNotEqual(p.wait(), 0)
796+
def test_terminate(self):
797+
self._kill_process('terminate')
791798

792799

793800
# The module says:

0 commit comments

Comments
 (0)