API Documentation#
- class hiro.Timeline(scale=1, start=None)[source]#
Timeline context manager. Within this context the following builtins respect the alterations made to the timeline:
The class can be used either as a context manager or a decorator.
The following are all valid ways to use it.
with Timeline(scale=10, start=datetime.datetime(2012,12,12)): .... fast_timeline = Timeline(scale=10).forward(120) with fast_timeline as timeline: .... delta = datetime.date(2015,1,1) - datetime.date.today() future_frozen_timeline = Timeline(scale=10000).freeze().forward(delta) with future_frozen_timeline as timeline: ... @Timeline(scale=100) def slow(): time.sleep(120)
- Parameters
scale¶ (float) – > 1 time will go faster and < 1 it will be slowed down.
start¶ – if specified starts the timeline at the given value (either a floating point representing seconds since epoch or a
datetime.datetime
object)
- forward(amount)[source]#
forwards the timeline by the specified
amount
- Parameters
amount¶ – either an integer representing seconds or a
datetime.timedelta
object
- freeze(target_time=None)[source]#
freezes the timeline
- Parameters
target_time¶ – the time to freeze at as either a float representing seconds since the epoch or a
datetime.datetime
object. If not provided time will be frozen at the current time of the enclosingTimeline
- rewind(amount)[source]#
rewinds the timeline by the specified
amount
- Parameters
amount¶ – either an integer representing seconds or a
datetime.timedelta
object
- hiro.run_sync(factor, func, *args, **kwargs)[source]#
Executes a callable within a
hiro.Timeline
- hiro.run_threaded(factor, func, *args, **kwargs)[source]#
Executes a callable in a separate thread within a
hiro.Timeline
- hiro.run_async(factor, func, *args, **kwargs)[source]#
Executes a callable in a separate thread within a
hiro.Timeline
- Parameters
- Returns
an instance of
hiro.core.ScaledAsyncRunner
Deprecated since version 1.0.0: Use
run_threaded()
- class hiro.core.ScaledRunner(factor, func, *args, **kwargs)[source]#
manages the execution of a callable within a
hiro.Timeline
context.
- class hiro.core.ScaledThreadedRunner(*args, **kwargs)[source]#
manages the threaded execution of a callable within a
hiro.Timeline
context.- get_execution_time()#
- Returns
the real execution time of
func
in seconds
- get_response()#
- Returns
the return value from
func
- Raises
Exception if the
func
raised one during execution
- hiro.core.ScaledAsyncRunner#
alias of
ScaledThreadedRunner