API

PySlot comes with two different signal classes:

class pyslot.Signal

A basic, synchronous, signal implementation.

Warning

This class is NOT thread-safe.

In particular, attempting to connect, disconnect or emit the signal simultaneously from different threads has unspecified behaviour.

If you need that kind of thread-safety and can pay the cost for it, look at the ThreadSafeSignal class instead.

connect(callback)

Connects a new callback to this signal.

Parameters:callback – The callback to connect.

callback will be called whenever emit gets called on the Signal instance.

A weak reference is kept, meaning that if the callback gets destroyed, it is unregistered from the signal automatically.

This design choice helps avoiding circular references in user-code.

Note

Connecting the same callback twice or more will cause the callback to be called several times per emit call.

You will have to call disconnect as many times as the connect call was called to unregister a callback completely.

disconnect(callback)

Disconnects a callback from this signal.

Parameters:callback – The callback to disconnect.

Warning

If the callback is not connected at the time of call, a ValueError exception is thrown.

Note

You may call disconnect from a connected callback.

emit(*args, **kwargs)

Emit the signal.

Parameters:
  • args – The arguments.
  • kwargs – The keyword arguments.

All the connected callbacks will be called synchronously in order of their registration.

class pyslot.ThreadSafeSignal

A thread-safe, synchronous, signal implementation.

Note

This class is thread-safe. You may connect, disconnect or emit the signal from different threads.

connect(callback)

Connects a new callback to this signal.

Parameters:callback – The callback to connect.

callback will be called whenever emit gets called on the Signal instance.

A weak reference is kept, meaning that if the callback gets destroyed, it is unregistered from the signal automatically.

This design choice helps avoiding circular references in user-code.

Note

Connecting the same callback twice or more will cause the callback to be called several times per emit call.

You will have to call disconnect as many times as the connect call was called to unregister a callback completely.

disconnect(callback)

Disconnects a callback from this signal.

Parameters:callback – The callback to disconnect.

Warning

If the callback is not connected at the time of call, a ValueError exception is thrown.

Note

You may call disconnect from a connected callback.

emit(*args, **kwargs)

Emit the signal.

Parameters:
  • args – The arguments.
  • kwargs – The keyword arguments.

All the connected callbacks will be called synchronously in order of their registration.