API reference

class mp_throttle.Throttle(max_n=0, per=1, **kwargs)[source]

Central object to store the multiprocessing shared objects and create the throttling and the monitoring process.

Parameters:
  • max_n (int) – Number of allowed processes per time unit ‘per’
  • per (int) – Time in seconds that max_n if reffering to.
  • **kwargs – See below
Keyword Arguments:
 
  • as_monitor (bool) – If True (default): Monitoring process will be created.
  • as_throttle (bool) – If True (default): Monitoring process will be created.
  • auto_emit (bool) – If True (default): A timestamp will be passed to the monitoring process, each time await_fuel() or has_fuel() is called. If False: emit() can be called by the processes to submit a timestamp to the monitoring process.
  • auto_calibrate (bool) – If True (default for max_n >= 49): and as_throttle = True and _correction not set manually: _calibrate() gets called when instatiating. If False (default for max_n <= 49): _calibrate() will not get called.
  • _correction (float) – Factor to reduce the frequency with which the gas queue is filled. If set manually, _calibrate() will not get called.
  • hardcap (str) – If ‘limit’ (default): The gas queue will never exceed max_n (Optimising latest frequency). If ‘one’: The gas queue will never exceed 1 (Preventig to ever exceed max_n processes per second) Else: The gas queue might exceed max_n when worker processes are slower (Optimising mean frequency).
  • rf_rate (float) – Time in second between each update of the monitoring process. Can not be 0. Defaul 0.01.
start()[source]

Starts the monitoring and throttle process and sets self.start_time.

stop()[source]

Stops the throttle and the monitoring process, empties the gas and the emission queue and resets the lates stats. Returns (runtime, total emissions, mean time between emissions, mean emissions per second)

has_fuel()[source]

Returns True if fuel is available, else False. For blocking unitl fuel is available use await_fuel()

await_fuel(t=None)[source]

Blocks the calling process until fuel is available (return True) or timeout seconds have passed (return False).

Parameters:t (float) – timeout in seconds. Default = None (unlimited timeout).
emit(timestamp=None)[source]

Passes a timestamp to the monitoring process. Can be called anywhere in each worker process, if self.auto_emit = False.

Parameters:timestamp (float (epoch-time)) – Optional: Submit a specific timestamp to the monitoring process. If not specified, time.time() will be submitted.
latest()[source]

Returns the stats of the last second as tuple (time between emissions, emissions per second)

mean()[source]

Returns the mean stats as tuple (mean time between emissions, mean emissions per second)

lo_hi()[source]

Returns the lowest time between emission and the highest emissions per second.

hi_lo()[source]

Returns the highest time between emission and the lowest emissions per second.

_calibrate()[source]

Calculates a correction thats is used to adapt the frequency in which fuel is put into the tank. If Throttle.auto_calibrate == True, this function is called when creating a Throttle object.