upsies.utils.daemon
Background workers to keep the UI responsive
Functions
- upsies.utils.daemon.maybe_terminate(input_queue)[source]
Read all queued items and raise
DaemonProcessTerminatedif there is a MsgType.terminatePut all other items back into the queue in the same order.
- upsies.utils.daemon.read_input_queue(input_queue, default=(None, None))[source]
Return single (<MsgType>, <payload data>) tuple from input_queue or default if it is empty
- upsies.utils.daemon.read_input_queue_key(input_queue, key)[source]
Read
dictfrom input_queue and return its value for key if it existsThe
dictmust be queued asMsgType.info.If MsgType.terminate is queued, raise
DaemonProcessTerminatedinstead of looking for key.Put all other items back into the queue in the same order.
- upsies.utils.daemon.read_input_queue_until_empty(input_queue)[source]
Keep reading input_queue until it is empty
Return the sequence of items that was read from the queue.
Raise
DaemonProcessTerminatedif there is a MsgType.terminate queued.
Classes
- class upsies.utils.daemon.DaemonProcess(target, name=None, args=(), kwargs={}, init_callback=None, info_callback=None, error_callback=None, result_callback=None, finished_callback=None)[source]
Bases:
objectmultiprocessing.Processabstraction with IPCIntended to offload heavy work (e.g. torrent creation) onto a different process. (Threads can still make the UI unresponsive because of the GIL.)
- send(typ, value)[source]
Send message to process if it is still alive
If
is_aliveis False, do nothing.- Parameters:
typ (MsgType) – General message category
value – Message string, payload, sentinel, etc.
- property exception
Exception from target or callback, None if no exception was raised