You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Type "help", "copyright", "credits" or "license"for more information.
415
+
>>> import asyncio
416
+
>>> import uvloop
417
+
>>>
418
+
>>> import my_async_module
419
+
>>>
420
+
>>> uvloop.install()
421
+
>>>
422
+
>>> async def main():
423
+
... await my_async_module.rust_sleep()
424
+
...
425
+
>>> asyncio.run(main())
426
+
>>>
427
+
```
428
+
429
+
#### Using `uvloop` in Rust Applications
430
+
431
+
Using `uvloop` in Rust applications is a bit trickier, but it's still possible
432
+
with relatively few modifications.
433
+
434
+
> Unfortunately, we can't make use of the `#[pyo3_asyncio::<runtime>::main]` attribute with non-standard event loops. This is because the `#[pyo3_asyncio::<runtime>::main]` proc macro has to interact with the Python
435
+
event loop before we can install the `uvloop` policy.
436
+
437
+
```toml
438
+
[dependencies]
439
+
async-std = "1.9"
440
+
pyo3 = "0.14"
441
+
pyo3-asyncio = { version = "0.14", features = ["async-std-runtime"] }
One problem that arises when interacting with Python's asyncio library is that the functions we use to get a reference to the Python event loop can only be called in certain contexts. Since PyO3 Asyncio needs to interact with Python's event loop during conversions, the context of these conversions can matter a lot.
0 commit comments