timing

Utilities for keeping track of time in a task.

class axopy.timing.Counter(max_count=1, reset_on_timeout=True)[source]

Counts to a given number then transmits a timeout event.

Parameters:
  • max_count (int) – Number of iterations to go through before transmitting the timeout event. Must be greater than 1.

  • reset_on_timeout (bool, optional) – Specifies whether or not the timer should reset its count back to zero once the timeout event occurs. The default behavior is to reset.

count

Current count.

Type:

int

timeout

Transmitted when max_count has been reached.

Type:

Transmitter

Examples

Basic usage:

>>> from axopy.timing import Counter
>>> timer = Counter(2)
>>> timer.increment()
>>> timer.count
1
>>> timer.progress
0.5
>>> timer.increment()
>>> timer.count
0
increment()[source]

Increment the counter.

If max_count is reached, the timeout event is transmitted. If reset_on_timeout has been set to True (default), the timer is also reset.

property progress

Progress toward timeout, from 0 to 1.

reset()[source]

Resets the count to 0 to start over.

class axopy.timing.Timer(duration)[source]

Real-time one-shot timer.

This is useful in situations where you want to wait for some amount of time and locking the timing to data acquisition updates is not important. For example, inserting a waiting period between trials of a task can be done by connecting the timeout transmitter to your task’s next_trial() method.

Parameters:

duration (float) – Duration of the timer, in seconds.

timeout

Transmitted when the timer has finished.

Type:

Transmitter

start()[source]

Start the timer.

stop()[source]

Stop the timer.

If you stop the timer early, the timeout event won’t be transmitted.