File tree Expand file tree Collapse file tree 5 files changed +17
-12
lines changed Expand file tree Collapse file tree 5 files changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ requirements:
2626 - greenlet ==1.1.2
2727 - pyee ==8.1.0
2828 - websockets ==10.1
29+ - psutil ==5.9.0 # [py<38]
2930 - typing_extensions # [py<39]
3031test :
3132 requires :
Original file line number Diff line number Diff line change @@ -195,7 +195,7 @@ async def stop_async(self) -> None:
195195 self .cleanup ()
196196
197197 def cleanup (self ) -> None :
198- if self ._init_task :
198+ if self ._init_task and not self . _init_task . done () :
199199 self ._init_task .cancel ()
200200 for ws_connection in self ._child_ws_connections :
201201 ws_connection ._transport .dispose ()
Original file line number Diff line number Diff line change @@ -110,7 +110,19 @@ def request_stop(self) -> None:
110110
111111 async def wait_until_stopped (self ) -> None :
112112 await self ._stopped_future
113- await self ._proc .wait ()
113+ # In Python 3.7, self._proc.wait() hangs because it does not use ThreadedChildWatcher
114+ # which is used in Python 3.8+. Hence waiting for child process is skipped in Python 3.7.
115+ # See https://bugs.python.org/issue35621
116+ # See https://stackoverflow.com/questions/28915607/does-asyncio-support-running-a-subprocess-from-a-non-main-thread/28917653#28917653
117+ if sys .version_info >= (3 , 8 ):
118+ await self ._proc .wait ()
119+ else :
120+ import psutil
121+
122+ try :
123+ psutil .Process (self ._proc .pid ).wait ()
124+ except psutil .NoSuchProcess :
125+ pass
114126
115127 async def connect (self ) -> None :
116128 self ._stopped_future : asyncio .Future = asyncio .Future ()
Original file line number Diff line number Diff line change 1313# limitations under the License.
1414
1515import asyncio
16- import sys
1716from typing import Any
1817
1918from greenlet import greenlet
@@ -74,15 +73,7 @@ def start(self) -> SyncPlaywright:
7473
7574 def __exit__ (self , * args : Any ) -> None :
7675 self ._connection .stop_sync ()
77- # In Python 3.7, self._connection._transport.wait_until_stopped() hangs because
78- # it does not uses ThreadedChildWatcher which is used in Python 3.8+.
79- # Hence waiting for child process is skipped in Python 3.7.
80- # See https://bugs.python.org/issue35621
81- # See https://stackoverflow.com/questions/28915607/does-asyncio-support-running-a-subprocess-from-a-non-main-thread/28917653#28917653
82- if sys .version_info >= (3 , 8 ):
83- self ._loop .run_until_complete (
84- self ._connection ._transport .wait_until_stopped ()
85- )
76+ self ._loop .run_until_complete (self ._connection ._transport .wait_until_stopped ())
8677 if self ._own_loop :
8778 self ._loop .run_until_complete (self ._loop .shutdown_asyncgens ())
8879 self ._loop .close ()
Original file line number Diff line number Diff line change @@ -212,6 +212,7 @@ def _download_and_extract_local_driver(
212212 "greenlet==1.1.2" ,
213213 "pyee==8.1.0" ,
214214 "typing-extensions;python_version<='3.8'" ,
215+ "psutil==5.9.0;python_version<='3.7'" ,
215216 ],
216217 classifiers = [
217218 "Topic :: Software Development :: Testing" ,
You can’t perform that action at this time.
0 commit comments