33import os
44import random
55import re
6- import signal
76import socket
8- import subprocess
97import sys
108import threading
119import time
1210import traceback
1311import unittest
1412
1513import psutil
14+ import subprocess32 as subprocess
1615
1716import mitogen .core
1817import mitogen .fork
@@ -71,30 +70,6 @@ def data_path(suffix):
7170 return path
7271
7372
74- def subprocess__check_output (* popenargs , ** kwargs ):
75- # Missing from 2.6.
76- process = subprocess .Popen (stdout = subprocess .PIPE , * popenargs , ** kwargs )
77- output , _ = process .communicate ()
78- retcode = process .poll ()
79- if retcode :
80- cmd = kwargs .get ("args" )
81- if cmd is None :
82- cmd = popenargs [0 ]
83- raise subprocess .CalledProcessError (retcode , cmd )
84- return output
85-
86-
87- def Popen__terminate (proc ):
88- os .kill (proc .pid , signal .SIGTERM )
89-
90-
91- if hasattr (subprocess , 'check_output' ):
92- subprocess__check_output = subprocess .check_output
93-
94- if hasattr (subprocess .Popen , 'terminate' ):
95- Popen__terminate = subprocess .Popen .terminate
96-
97-
9873def threading__thread_is_alive (thread ):
9974 """Return whether the thread is alive (Python version compatibility shim).
10075
@@ -457,7 +432,7 @@ def get_docker_host():
457432
458433class DockerizedSshDaemon (object ):
459434 def _get_container_port (self ):
460- s = subprocess__check_output (['docker' , 'port' , self .container_name ])
435+ s = subprocess . check_output (['docker' , 'port' , self .container_name ])
461436 for line in s .decode ().splitlines ():
462437 m = self .PORT_RE .match (line )
463438 if not m :
@@ -472,7 +447,7 @@ def _get_container_port(self):
472447
473448 def start_container (self ):
474449 try :
475- subprocess__check_output (['docker' , '--version' ])
450+ subprocess . check_output (['docker' , '--version' ])
476451 except Exception :
477452 raise unittest .SkipTest ('Docker binary is unavailable' )
478453
@@ -486,7 +461,7 @@ def start_container(self):
486461 '--name' , self .container_name ,
487462 self .image ,
488463 ]
489- subprocess__check_output (args )
464+ subprocess . check_output (args )
490465 self ._get_container_port ()
491466
492467 def __init__ (self , mitogen_test_distro = os .environ .get ('MITOGEN_TEST_DISTRO' , 'debian9' )):
@@ -518,7 +493,7 @@ def wait_for_sshd(self):
518493 def check_processes (self ):
519494 args = ['docker' , 'exec' , self .container_name , 'ps' , '-o' , 'comm=' ]
520495 counts = {}
521- for comm in subprocess__check_output (args ).decode ().splitlines ():
496+ for comm in subprocess . check_output (args ).decode ().splitlines ():
522497 comm = comm .strip ()
523498 counts [comm ] = counts .get (comm , 0 ) + 1
524499
@@ -533,7 +508,7 @@ def check_processes(self):
533508
534509 def close (self ):
535510 args = ['docker' , 'rm' , '-f' , self .container_name ]
536- subprocess__check_output (args )
511+ subprocess . check_output (args )
537512
538513
539514class BrokerMixin (object ):
0 commit comments