Skip to content

fix(exit): fix the task pending error on async context manager closure #519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion playwright/_impl/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ def stop_sync(self) -> None:
self._transport.stop()
self._dispatcher_fiber.switch()

def stop_async(self) -> None:
async def stop_async(self) -> None:
self._transport.stop()
await self._transport.wait_until_stopped()

async def wait_for_object_with_known_name(self, guid: str) -> Any:
if guid in self._objects:
Expand Down
5 changes: 5 additions & 0 deletions playwright/_impl/_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ def stop(self) -> None:
self._stopped = True
self._output.close()

async def wait_until_stopped(self) -> None:
await self._stopped_future

async def run(self) -> None:
self._loop = asyncio.get_running_loop()
self._stopped_future: asyncio.Future = asyncio.Future()

driver_env = os.environ.copy()
# VSCode's JavaScript Debug Terminal provides it but driver/pkg does not support it
Expand Down Expand Up @@ -87,6 +91,7 @@ async def run(self) -> None:
except asyncio.IncompleteReadError:
break
await asyncio.sleep(0)
self._stopped_future.set_result(None)

def send(self, message: Dict) -> None:
msg = json.dumps(message)
Expand Down
2 changes: 1 addition & 1 deletion playwright/async_api/_context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ async def start(self) -> AsyncPlaywright:
return await self.__aenter__()

async def __aexit__(self, *args: Any) -> None:
self._connection.stop_async()
await self._connection.stop_async()