Overview
Theloop() function creates and sets a new asyncio event loop. This is a convenience function for running nodriver’s async functions in a synchronous context.
Signature
Returns
A new asyncio event loop that you can use to run async functions.
Examples
Basic usage
Running multiple coroutines
Alternative: Using asyncio directly
You can also use Python’s built-inasyncio.run() (Python 3.7+):
Notes
The
loop() function is a convenience wrapper around asyncio.new_event_loop() and asyncio.set_event_loop().In Python 3.7+, you can use
asyncio.run() instead of uc.loop().run_until_complete() for simpler code.See also
- start() - Launch a browser instance
- Python asyncio documentation - Learn more about async programming