traits_futures.asyncio.pingee module

asyncio cross-thread pinger.

This module provides a way for a background thread to request that the main thread execute a (fixed, parameterless) callback.

class traits_futures.asyncio.pingee.Pingee(on_ping, event_loop)[source]

Bases: object

Receiver for pings.

Whenever a ping is received from a linked Pinger, the receiver calls the given fixed parameterless callable.

The ping receiver must be connected (using the connect) method before use, and should call disconnect when it’s no longer expected to receive pings.

Parameters:
  • on_ping – Zero-argument callable that’s called on the main thread every time a ping is received.

  • event_loop (asyncio.AbstractEventLoop) – The asyncio event loop that pings will be sent to.

connect()[source]

Prepare Pingee to receive pings.

disconnect()[source]

Disconnect from the on_ping callable.

pinger()[source]

Create and return a new pinger linked to this pingee.

This method is thread-safe. Typically the pingee will be passed to a background thread, and this method used within that background thread to create a pinger.

This method should only be called after the ‘connect’ method has been called.

Returns:

pinger – New pinger, linked to this pingee.

Return type:

Pinger

class traits_futures.asyncio.pingee.Pinger(pingee, event_loop)[source]

Bases: object

Ping emitter, which can send pings to a receiver in a thread-safe manner.

Parameters:
  • pingee (Pingee) – The target receiver for the pings. The receiver must already be connected.

  • event_loop (asyncio.AbstractEventLoop) – The asyncio event loop that will execute the ping callback.

connect()[source]

Connect to the ping receiver. No pings should be sent until this function is called.

disconnect()[source]

Disconnect from the ping receiver. No pings should be sent after calling this function.

ping()[source]

Send a ping to the receiver.