Skip to main content

AsyncThread

Class for running an asyncio event loop in a separate thread.

This allows running asynchronous coroutines from synchronous code by executingthem on an event loop that runs in its own dedicated thread.

Index

Methods

__init__

  • __init__(): None
  • Returns None

close

  • close(timeout): None
  • Close the event loop and its thread gracefully.

    This method cancels all pending tasks, stops the event loop, and waits for the thread to exit. If the thread does not exit within the given timeout, a forced shutdown is attempted.


    Parameters

    • optionaltimeout: timedelta = timedelta(seconds=60)

      The maximum number of seconds to wait for the event loop thread to exit.

    Returns None

run_coro

  • run_coro(coro, timeout): Any
  • Run a coroutine on an event loop running in a separate thread.

    This method schedules the coroutine to run on the event loop and blocks until the coroutine completes or the specified timeout is reached.


    Parameters

    • coro: Coroutine

      The coroutine to run.

    • optionaltimeout: timedelta = timedelta(seconds=60)

      The maximum number of seconds to wait for the coroutine to finish.

    Returns Any

Page Options