Skip to content

Commit de2b3d3

Browse files
committed
cleanups
1 parent 107c432 commit de2b3d3

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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]
3031
test:
3132
requires:

playwright/_impl/_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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()

playwright/_impl/_transport.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff 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()

playwright/sync_api/_context_manager.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
import asyncio
16-
import sys
1716
from typing import Any
1817

1918
from 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()

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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",

0 commit comments

Comments
 (0)