Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

docs(python): document that task cancellation is not supported (#42312)

Yury Semikhatsky642dcfd46c24
diff --git a/docs/src/library-python.md b/docs/src/library-python.md
index 9dcf0cba99..6ec0eeb1db 100644
--- a/docs/src/library-python.md
+++ b/docs/src/library-python.md
@@ -199,3 +199,7 @@ On Windows Python 3.7, Playwright sets the default event loop to `ProactorEventL
### Threading
Playwright's API is not thread-safe. If you are using Playwright in a multi-threaded environment, you should create a playwright instance per thread. See [threading issue](https://github.com/microsoft/playwright-python/issues/623) for more details.
+
+### Cancelling `asyncio` tasks
+
+Cancelling a task that is running a Playwright call is not supported and results in undefined behavior. If an operation has to outlive its caller, run it in a separate task and protect it with [`asyncio.shield()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.shield).