11import contextlib
22import os
3+ import sys
4+ import platform
35import subprocess
46import tempfile
57import time
810import psutil
911
1012# Path to the test data folder.
11- TEST_DATA_DIR = Path (__file__ ).parent / ' data'
13+ TEST_DATA_DIR = Path (__file__ ).parent / " data"
1214
1315
1416def get_process_listening_port (proc ):
15- psutil_proc = psutil .Process (proc .pid )
16- while not any (conn .status == 'LISTEN' for conn in psutil_proc .connections ()):
17- time .sleep (0.01 )
18-
19- conn = next (filter (lambda conn : conn .status == 'LISTEN' , psutil_proc .connections ()))
17+ conn = None
18+ if platform .system () == "Windows" :
19+ current_process = psutil .Process (proc .pid )
20+ children = []
21+ while children == []:
22+ time .sleep (0.01 )
23+ children = current_process .children (recursive = True )
24+ if (3 , 6 ) <= sys .version_info < (3 , 7 ):
25+ children = [current_process ]
26+ for child in children :
27+ while child .connections () == [] and not any (conn .status == "LISTEN" for conn in child .connections ()):
28+ time .sleep (0.01 )
29+
30+ conn = next (filter (lambda conn : conn .status == "LISTEN" , child .connections ()))
31+ else :
32+ psutil_proc = psutil .Process (proc .pid )
33+ while not any (conn .status == "LISTEN" for conn in psutil_proc .connections ()):
34+ time .sleep (0.01 )
35+
36+ conn = next (filter (lambda conn : conn .status == "LISTEN" , psutil_proc .connections ()))
2037 return conn .laddr .port
2138
2239
@@ -40,8 +57,10 @@ def get_eel_server(example_py, start_html):
4057
4158import { os .path .splitext (os .path .basename (example_py ))[0 ]}
4259""" )
43-
44- proc = subprocess .Popen (['python' , test .name ], cwd = os .path .dirname (example_py ))
60+ proc = subprocess .Popen (
61+ [sys .executable , test .name ],
62+ cwd = os .path .dirname (example_py ),
63+ )
4564 eel_port = get_process_listening_port (proc )
4665
4766 yield f"http://localhost:{ eel_port } /{ start_html } "
0 commit comments