API Documentation¶
-
class
hiro.Timeline(scale=1, start=None)[source]¶ Timeline context manager. Within this context the builtins
time.time(),time.sleep(),datetime.datetime.now(),datetime.date.today(),datetime.datetime.utcnow()andtime.gmtime()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.datetimeobject)
-
forward(amount)[source]¶ forwards the timeline by the specified
amountParameters: amount – either an integer representing seconds or a datetime.timedeltaobject
-
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.datetimeobject. If not provided time will be frozen at the current time of the enclosingTimeline
-
rewind(amount)[source]¶ rewinds the timeline by the specified
amountParameters: amount – either an integer representing seconds or a datetime.timedeltaobject
-
hiro.run_async(factor, func, *args, **kwargs)[source]¶ Asynchronously executes a callable within a
hiro.TimelineParameters: - factor (int) – scale factor to use for the timeline during execution
- func (function) – the function to invoke
- args – the arguments to pass to the function
- kwargs – the keyword arguments to pass to the function
Returns: an instance of
hiro.core.ScaledAsyncRunner
-
hiro.run_sync(factor, func, *args, **kwargs)[source]¶ Executes a callable within a
hiro.TimelineParameters: - factor (int) – scale factor to use for the timeline during execution
- func (function) – the function to invoke
- args – the arguments to pass to the function
- kwargs – the keyword arguments to pass to the function
Returns: an instance of
hiro.core.ScaledRunner
-
class
hiro.core.ScaledRunner(factor, func, *args, **kwargs)[source]¶ manages the execution of a callable within a
hiro.Timelinecontext.
-
class
hiro.core.ScaledAsyncRunner(*args, **kwargs)[source]¶ manages the asynchronous execution of a callable within a
hiro.Timelinecontext.-
get_execution_time()¶ Returns: the real execution time of funcin seconds
-
get_response()¶ Returns: the return value from funcRaises: Exception if the funcraised one during execution
-