pyodide.webloop#

Classes:

WebLoop()

A custom event loop for use in Pyodide.

WebLoopPolicy()

A simple event loop policy for managing WebLoop based event loops.

class pyodide.webloop.WebLoop#

A custom event loop for use in Pyodide.

Schedules tasks on the browser event loop. Does no lifecycle management and runs forever.

run_forever and run_until_complete cannot block like a normal event loop would because we only have one thread so blocking would stall the browser event loop and prevent anything from ever happening.

We defer all work to the browser event loop using the setTimeout function. To ensure that this event loop doesn’t stall out UI and other browser handling, we want to make sure that each task is scheduled on the browser event loop as a task not as a microtask. setTimeout(callback, 0) enqueues the callback as a task so it works well for our purposes.

See Event Loop Methods.

class pyodide.webloop.WebLoopPolicy#

A simple event loop policy for managing WebLoop based event loops.