Interface PythonEventLoop
- All Known Implementing Classes:
NettyPythonEventLoop
Event-loop operations required to drive Micronaut-managed Python asyncio tasks.
-
Method Summary
Modifier and TypeMethodDescriptionvoidQueue a callback for serialized execution on the loop.default voidexecuteCallback(org.graalvm.polyglot.Value callback) Queue a Python callback for execution on the loop.booleanUsed to decide whether Python work can run immediately or must be queued.Queue a callback after the requested delay using loop time.default ScheduledFuture<?> scheduleCallback(org.graalvm.polyglot.Value callback, long delay, TimeUnit unit) Queue a Python callback after the requested delay using loop time.doubletime()Returns the monotonic time base exposed to Python's asyncio APIs.
-
Method Details
-
inEventLoop
boolean inEventLoop()Used to decide whether Python work can run immediately or must be queued.- Returns:
- Whether the current thread is this event-loop thread.
-
execute
Queue a callback for serialized execution on the loop.- Parameters:
runnable- The callback.
-
schedule
Queue a callback after the requested delay using loop time.- Parameters:
runnable- The callback.delay- The delay.unit- The delay unit.- Returns:
- The scheduled future.
-
executeCallback
default void executeCallback(org.graalvm.polyglot.Value callback) Queue a Python callback for execution on the loop.A loop that owns a GraalPy context runs the callback inside an execution frame of the callback's context, so shutdown waits for callbacks scheduled with
call_soon. ThePropagatedContextof the callback is not captured here: it belongs to the asyncio task that owns the callback, which keeps it in itscontextvarsand restores it when the callback runs, so a task resumed by another task (a sharedasyncio.Event) or by a Java thread completing an awaited stage keeps its own context.- Parameters:
callback- The Python callable.
-
scheduleCallback
default ScheduledFuture<?> scheduleCallback(org.graalvm.polyglot.Value callback, long delay, TimeUnit unit) Queue a Python callback after the requested delay using loop time.- Parameters:
callback- The Python callable.delay- The delay.unit- The delay unit.- Returns:
- The scheduled future.
-
time
double time()Returns the monotonic time base exposed to Python's asyncio APIs.- Returns:
- Event-loop time in seconds.
-