Supported by Supported by

Clock functions

class clock

The clock offers basic time functions.

Example:

# Get the timestamp before and after sleeping for 1000 ms
t0 = clock.time()
clock.sleep(1000)
t1 = clock.time()
time_passed = t1 - t0
print(u'This should be 1000: %s' % time_passed)

function clock.__init__(experiment)

Constructor to create a new clock object. You do not generally call this constructor directly, because a clock object is created automatically when the experiment is launched.

Arguments:

function clock.sleep(ms)

Sleeps (pauses) for a period.

Example:

# Create two canvas objects ...
my_canvas1 = canvas()
my_canvas1.text(u'1')
my_canvas2 = canvas()
my_canvas2.text(u'2')
# ... and show them with 1 s in between
my_canvas1.show()
clock.sleep(1000)
my_canvas2.show()

Arguments:

  • ms -- The number of milliseconds to sleep for.
    • Type: int, float

function clock.time()

Gives a current timestamp in milliseconds. The absolute meaning of the timestamp (i.e. when it was 0) depends on the backend.

Example:

t = clock.time()
print(u'The current time is %f' % t)

Returns:

A timestamp.

  • Type: float