Skip to content

Signals

Attributes

REGISTERED_SIGNALS

REGISTERED_SIGNALS: dict[int, SignalDescription] = {}

Registered signals.


Functions

get_available_num

get_available_num() -> int

Returns first available signal number.

UwsgiconfException If no signal is available.


get_last_received

get_last_received() -> Signal

Get the last signal received.


Classes

Signal

Signal(num: int | None = None)

Represents uWSGI signal.

Warning

If you define a new function in worker1 and register it as a signal handler, only worker1 can run it. The best way to register signals is defining them in the master (.runtime.uwsgi.postfork_hooks.add), so all workers see them.

signal = Signal()

@signal.register_handler()
def somefunc():
    pass

# or the same:

@signal
def somefunc():
    pass

registered

.registered()

Whether the signal is registered.


register_handler

1
2
3
4
.register_handler(
    target: TypeTarget = None,  # (1)!
    callback: Callable[[Signal],  None] | None = None,  # (2)!
) -> Callable
  1. Where this signal will be delivered to. Default: worker.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    * Mule / Farm object - run on a certain mule or a farm.
    * ``workers``  - run the signal handler on all the workers
    * ``workerN`` - run the signal handler only on worker N
    * ``worker``/``worker0`` - run the signal handler on the first available worker
    * ``active-workers`` - run the signal handlers on all the active [non-cheaped] workers
    
    * ``mules`` - run the signal handler on all the mules
    * ``muleN`` - run the signal handler on mule N
    * ``mule``/``mule0`` - run the signal handler on the first available mule
    
    * ``spooler`` - run the signal on the first available spooler
    * ``farmN/farm_XXX``  - run the signal handler in the mule farm N or named XXX
    
    * <http://uwsgi.readthedocs.io/en/latest/Signals.html#signals-targets>
    
  2. Function to be called after the registration.

Decorator for a function to be used as a signal handler.

1
2
3
4
5
signal = Signal()

@signal.register_handler()
def somefunc():
    pass

send

1
2
3
.send(
    remote: str | None = None,  # (1)!
)
  1. Remote address.

Sends the signal to master or remote.

When you send a signal, it is copied into the master's queue. The master will then check the signal table and dispatch the messages.

ValueError If remote rejected the signal.

OSError If unable to deliver to remote.


wait

.wait()

Waits for the given of any signal.

Block the process/thread/async core until a signal is received. Use signal_received to get the number of the signal received. If a registered handler handles a signal, signal_wait will be interrupted and the actual handler will handle the signal.

SystemError If something went wrong.


SignalDescription

SignalDescription()

NamedTuple

Registered signal information.


func

.func: Callable

Function to run on signal.


num

.num: int

Signal number.


target

.target: str

Target: worker, mule, etc.