OpenSesame videos
Python videos

Clock functions

instance clock

The clock object offers basic time functions. A clock object is created automatically when the experiment starts.

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.loop_for(ms, throttle=None, t0=None)

New in v3.2.0

An iterator that loops for a fixed time.

Example:

for ms in clock.sleep_for(100, throttle=10):
        print(ms)

Arguments:

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

Keywords:

  • throttle -- A period to sleep for in between each iteration.
    • Type: NoneType, float, int
    • Default: None
  • t0 -- A starting time. If None, the starting time is the moment at which the iteration starts.
    • Type: NoneType, float, int
    • Default: None

Returns:

An Iterator over times in milliseconds that have passed since t0.

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
Supported by Supported by