Interface PythonEventLoop

All Known Implementing Classes:
NettyPythonEventLoop

@Internal public interface PythonEventLoop
Event-loop operations required to drive Micronaut-managed Python asyncio tasks.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    execute(Runnable runnable)
    Queue a callback for serialized execution on the loop.
    default void
    executeCallback(org.graalvm.polyglot.Value callback)
    Queue a Python callback for execution on the loop.
    boolean
    Used to decide whether Python work can run immediately or must be queued.
    schedule(Runnable runnable, long delay, TimeUnit unit)
    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.
    double
    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

      void execute(Runnable runnable)
      Queue a callback for serialized execution on the loop.
      Parameters:
      runnable - The callback.
    • schedule

      ScheduledFuture<?> schedule(Runnable runnable, long delay, TimeUnit unit)
      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. The PropagatedContext of the callback is not captured here: it belongs to the asyncio task that owns the callback, which keeps it in its contextvars and restores it when the callback runs, so a task resumed by another task (a shared asyncio.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.