jztools.parallelization.threading.queue#

Event-interruptible queue put and get loops.

Parameters

Todo

Works for multiprocessing too. Move this to another place (not the threading module).

Module Attributes

DEFAULT_TIMEOUT

Default timeout value used by put_loop() and get_loop().

Functions

check_exit_events(exit_events)

Raises a: exc: LoopExitRequested if one of the exit events is set.

get_loop(q, exit_events[, timeout, pre_check])

Attempts to get an item from the queue, checking if an exit event was raised every timeout seconds.

put_loop(q, item, exit_events[, timeout, ...])

Attempts to put an item in the queue, checking if an exit event was raised every timeout seconds.

jztools.parallelization.threading.queue.DEFAULT_TIMEOUT = 0.1#

Default timeout value used by put_loop() and get_loop().

jztools.parallelization.threading.queue.check_exit_events(exit_events)#

Raises a: exc: LoopExitRequested if one of the exit events is set.

jztools.parallelization.threading.queue.put_loop(q, item, exit_events: Dict[str, Event], timeout=0.1, pre_check=False)#

Attempts to put an item in the queue, checking if an exit event was raised every timeout seconds. See: ref: parameters.

Parameters:
  • q – The queue.

  • item – The item to put in the queue.

  • timeout – Exit events will be checked every timeout seconds.

  • exit_events – A dictionary of events signaling an exit, with the key being a user-friendly name.

  • pre_check – Checks that none of the exit events are set before attempting to put an item. If False, (the default), this check only happens after a timeout.

jztools.parallelization.threading.queue.get_loop(q, exit_events, timeout=0.1, pre_check=False)#

Attempts to get an item from the queue, checking if an exit event was raised every timeout seconds. See: ref: parameters.

Parameters:
  • q – The queue.

  • timeout – Exit events will be checked every timeout seconds.

  • exit_events – A dictionary of events signaling an exit, with the key being a user-friendly name.

  • pre_check – Checks that none of the exit events are set before attempting to put an item. If False, (the default), this check only happens after a timeout.