@@ -50,20 +50,19 @@ def decorated(self, *args, **kwargs):
5050 return decorated
5151
5252
53- def clean_processes (processes ):
54- for p in processes :
55- if getattr (p , 'exitcode' , None ) is None and getattr (p , 'returncode' , None ) is None :
56- # ask nicely (to try and catch the children)
57- try :
58- p .terminate () # SIGTERM
59- except OSError :
60- pass
61- time .sleep (1 )
62- # send a forcible kill immediately afterwards. If the process did not die before, this should clean it.
63- try :
64- p .terminate () # SIGKILL
65- except OSError :
66- pass
53+ def clean_process (p ):
54+ if getattr (p , 'exitcode' , None ) is None and getattr (p , 'returncode' , None ) is None :
55+ # ask nicely (to try and catch the children)
56+ try :
57+ p .terminate () # SIGTERM
58+ except OSError :
59+ pass
60+ time .sleep (1 )
61+ # send a forcible kill immediately afterwards. If the process did not die before, this should clean it.
62+ try :
63+ p .terminate () # SIGKILL
64+ except OSError :
65+ pass
6766
6867
6968class WebsockifyServerHarness :
@@ -112,7 +111,6 @@ def __enter__(self):
112111 except OSError :
113112 time .sleep (1 )
114113 else :
115- clean_processes (self .processes )
116114 raise Exception ('[Websockify failed to start up in a timely manner]' )
117115
118116 print ('[Websockify on process %s]' % str (self .processes [- 2 :]))
@@ -125,12 +123,13 @@ def __exit__(self, *args, **kwargs):
125123 self .websockify .join ()
126124
127125 # clean up any processes we started
128- clean_processes (self .processes )
126+ for p in self .processes :
127+ clean_process (p )
129128
130129
131130class CompiledServerHarness :
132131 def __init__ (self , filename , args , listen_port ):
133- self .processes = []
132+ self .process = None
134133 self .filename = filename
135134 self .listen_port = listen_port
136135 self .args = args or []
@@ -149,13 +148,11 @@ def __enter__(self):
149148 proc = run_process ([EMCC , '-Werror' , test_file (self .filename ), '-o' , 'server' + suffix , '-DSOCKK=%d' % self .listen_port ] + self .args )
150149 print ('Socket server build: out:' , proc .stdout or '' , '/ err:' , proc .stderr or '' )
151150
152- process = Popen (config .NODE_JS + ['server' + suffix ])
153- self .processes .append (process )
151+ self .process = Popen (config .NODE_JS + ['server' + suffix ])
154152 return self
155153
156154 def __exit__ (self , * args , ** kwargs ):
157- # clean up any processes we started
158- clean_processes (self .processes )
155+ clean_process (self .process )
159156
160157 # always run these tests last
161158 # make sure to use different ports in each one because it takes a while for the processes to be cleaned up
@@ -164,17 +161,16 @@ def __exit__(self, *args, **kwargs):
164161# Executes a native executable server process
165162class BackgroundServerProcess :
166163 def __init__ (self , args ):
167- self .processes = []
164+ self .process = None
168165 self .args = args
169166
170167 def __enter__ (self ):
171168 print ('Running background server: ' + str (self .args ))
172- process = Popen (self .args )
173- self .processes .append (process )
169+ self .process = Popen (self .args )
174170 return self
175171
176172 def __exit__ (self , * args , ** kwargs ):
177- clean_processes (self .processes )
173+ clean_process (self .process )
178174
179175
180176def NodeJsWebSocketEchoServerProcess ():
0 commit comments