hio.base package

Submodules

hio.base.basing module

hio.base.basing Module

class hio.base.basing.State(tyme, context, feed, count)

Bases: tuple

context

Alias for field number 1

count

Alias for field number 3

feed

Alias for field number 2

tyme

Alias for field number 0

hio.base.doing module

hio.core.doing Module

class hio.base.doing.Deed(dog, retyme, doer)

Bases: tuple

doer

Alias for field number 2

dog

Alias for field number 0

retyme

Alias for field number 1

class hio.base.doing.DoDoer(doers=None, always=False, **kwa)

Bases: Doer

DoDoer implements Doist like functionality to allow nested scheduling of Doers. Each DoDoer runs a list of doers like a Doist but using the tyme from its injected tymth for the associated tymist as injected by its ultimate root parent Doist and any intervening parent DoDoer(s).

Scheduling hierarchy: Doist->DoDoer…->DoDoer->Doers

Inherited Attributes:

done (bool): completion state:
            True means completed
            Otherwise incomplete. Incompletion maybe due to close or abort.
opts (dict): injected options for its generator .do
temp (bool | None): use temporary file resources if any

Attributes:

None

Inherited Properties:

- tyme is float relative cycle time of associated Tymist .tyme obtained
    via injected .tymth function wrapper closure.
- tymth is function wrapper closure returned by Tymist .tymeth() method.
    When .tymth is called it returns associated Tymist .tyme.
    .tymth provides injected dependency on Tymist tyme base.
- tock is float, desired time in seconds between runs or until next run,
    non negative, zero means run asap

Properties:

doers (list): Doer or Doist compatible generator instances,
    functions, or methods.
deeds (deque):  tuples of form (dog, retyme, doer)  where:
    dog is generator created by doer.
    retyme is tyme in seconds when next should run may be real or simulated.
    doer is associated doer in .doers list.
    Used throughout the execution lifecycle. The normal
    case is use the default empty initialization performed here and
    update in .enter().
always (bool): True means keep running even when all dogs in deeds
    are complete. Enables dynamically managing extending or removing
    doers and associated deeds while running.

Inherited Methods:

- wind: injects ._tymth dependency from associated Tymist to get its .tyme
- __call__: makes instance callable. Appears as generator function
    that returns generator
- do: is generator method that returns generator
- enter: is enter context action method
- recur: is recur context action method or generator method
- clean: is clean context action method
- exit: is exit context method
- close: is close context method
- abort: is abort context method

Overidden Methods:

- do
- enter
- recur
- exit

Hidden:

- _tymth is injected function wrapper closure returned by .tymen() of
   associated Tymist instance that returns Tymist .tyme. when called.
- _tock is hidden attribute for .tock property
- _always is hidden attribute for .always property
- _doers is hidden attribute for .doers property
- _deeds is hidden attribute for .deeds property
__init__(doers=None, always=False, **kwa)

Initialize instance.

Inherited Parameters:

tymth is injected function wrapper closure returned by .tymen() of
    Tymist instance. Calling tymth() returns associated Tymist .tyme.
tock is float seconds initial value of .tock

Parameters:

doers (iterable): Doer class instances, generator methods or function
    callables with attributes tock, done, and opts dict() used to
    initialize .doers.
    The .doers attribute is used throughout the execution lifecycle.
    Parameterization elsewhere of doers enables some special cases.
    The normal case is to initialize here.

always is Boolean, True means keep running even when all dogs in deeds
    are complete. Enables dynamically managing extending or removing
    doers and associated deeds while running.
property always

always property getter, get ._always .always is Boolean, True means keep running even when all dogs in deeds are complete. Enables dynamically managing extending or removing doers and associated deeds while running.

property deeds

deeds property getter, get ._deeds .deeds is deque of triples, each of form (dog, retyme, doer).

do(tymth, tock=0.0, doers=None, always=None, *, temp=None, **opts)

Generator method to run this doer. Equivalent of doist.do Calling this method returns generator Interface matched generator function for compatibility

Parameters:

tymth (closure): injected function wrapper closure returned by
    Tymist.tymen(). Calling tymth() returns associated Tymist.tyme.
tock (float): injected initial tock value
doers (list): of generator method or function callables with attributes
    tock, done, and opts dict(). This may be used to update the .doers
    attribute which is used throughout the execution lifecycle.
    If not provided uses .doers.
    Parameterization here of doers enables some special cases.
    The normal case is to initialize in .__init__.
always (bool): True means keep running even when all dogs in deeds
    are complete. Enables dynamically managing extending or removing
    doers and associated deeds while running.
    When not provided use .always.
temp (bool): True means use temporary file resources if any
opts (dict): injected optional additional parameters
property doers

doers property getter, get ._doers .doers is list of doist compatible generator instances, functions, or methods.

enter(doers=None, *, temp=None)

Do ‘enter’ context actions. Equivalent of Doist.enter() Set up resources. Comparable to context manager enter.

Returns deeds deque of triples (dog, retyme, doer) where:

dog is generator created by doer retyme is tyme in seconds when next should run may be real or simulated doer is doer for dog from doers list

Calls each generator callable (function or method) in .doers to create each generator dog.

Runs enter context of each dog by calling next(dog)

Parameters:

doers (list): Doer Instance, generator method or function callables
    with attributes tock, done, and opts dict().
    If not provided uses .doers.
    Parameterization here of doers enables some special cases.
    The normal case is to initialize in .__init__.

temp (bool | None): True means use temporary file resources if any
                    None means ignore parameter value. Use self.temp

Inject temp or self.temp into file resources here if any

Returns:

deeds (deque): A deed is tuple of form (dog, retyme, doer).
               If not provided uses .deeds.

See: https://stackoverflow.com/questions/40528867/setting-attributes-on-func For setting attributes on bound methods.

exit(deeds=None)

Do ‘exit’ context actions.

Parameters:

deeds (deque): of deed tuples of form (dog, retyme, doer)
    If not provided uses .deeds.
    Parameterization here of deeds enables some special cases.

See: https://stackoverflow.com/questions/40528867/setting-attributes-on-func For setting attributes on bound methods.

extend(doers)

Extend .doers list with doers. Ready deeds from doers and extend .doers and .deeds. Edit deeds in place so not replace deque.

Parameters:

doers is list of doers to add as extension.
recur(tyme, deeds=None)

Do ‘recur’ context actions. Equivalent of Doist.recur

Time value is output of send fed to do yield. Doist feeds its .tyme down the chain of DoDoers. Because tymist is injected by doist or dodoer, self.tyme is same as tyme. So may use either which is more convenient. Deeds are tuples of form (dog, retyme, doer). If not provided uses .deeds. Parameterization here of deeds enables some special cases.

Returns completion state of recurrence actions.

True means done False means continue

Cycle once through deeds deque and update in place

Each cycle checks all generators dogs in deeds deque and runs if retyme past.

remove(doers)

Remove doers from .doers list and any associated deeds from .deeds deque. Force close removed deeds.

Parameters:

doers is list of doers to remove.
class hio.base.doing.Doer(*, tymth=None, tock=0.0, opts=None, temp=False, **kwa)

Bases: Tymee

Doer base class for hierarchical structured async coroutine like generators. Doer.__call__ on instance returns generator. Interface for Doist etc is generator function like object. Doer is generator method instance creator and has extra methods and attributes that a plain generator function does not

The .do method executes other methods each corresponding to one of the six econtexts:

enter, recur, clean, exit, cease (forced), abort (forced)
Actual context order may be one of:

enter, recur, clean, exit enter, recur, cease, exit enter, recur, abort, exit enter, abort, exit

Attributes:

done (bool): completion state:
    True means completed
    Otherwise incomplete. Incompletion maybe due to close or abort.
opts (dict): injected options into its .do generator by scheduler
temp (bool): True means use temporary file resources if any

Inherited Properties:

tyme (float): is float relative cycle time of associated Tymist .tyme obtained
    via injected .tymth function wrapper closure.
tymth (closure): function wrapper closure returned by Tymist.tymen()
                method. When .tymth is called it returns associated
                Tymist.tyme. Provides injected dependency on Tymist
                tyme base.

Properties:

tock (float): desired time in seconds between runs or until next run,
         non negative, zero means run asap

Inherited Methods:

wind  injects ._tymth dependency from associated Tymist to get its .tyme

Methods:

- __call__: makes instance callable. Appears as generator function
    that returns generator
- do: generator method that returns generator
- enter: enter context action method
- recur: recur context action method or generator method
- clean: clean context action method
- exit: exit context method
- cease: cease context method
- abort: abort context method

Hidden:

_tymth (closure): is injected function wrapper closure returned by .tymen() of
    associated Tymist instance that returns Tymist .tyme. when called.
_tock (float): is hidden attribute for .tock property
__init__(*, tymth=None, tock=0.0, opts=None, temp=False, **kwa)

Initialize instance.

Inherited Parameters:

tymth (closure): injected function wrapper closure returned by .tymen() of
    Tymist instance. Calling tymth() returns associated Tymist .tyme.

Parameters:

tock (float): seconds initial value of .tock
opts (dict): injected options into its .do generator by scheduler
temp (bool): True means use temporary file resources if any
abort(ex)

Do ‘abort’ context actions. Override in subclass. Not a generator method. Parameters:

ex is Exception instance that caused abort.

Unexpected exception that results in generator exiting but not GeneratorExit. .exit() is finally called after .abort().

cease()

Do ‘cease’ context actions. Forced exist. Override in subclass. Not a generator method. Forced cease by thrown generator.close() method causing GeneratorExit. .exit() is finally called after .cease().

clean()

Do ‘clean’ context actions. Override in subclass. Not a generator method. Clean up resources that are unique to a clean exit. Called by else after normal return.

do(tymth, *, tock=0.0, temp=None, **opts)

Generator method to run this doer. Calling this method returns generator. Interface matches generator function for compatibility. To customize create subclasses and override the lifecycle methods:

- enter
- recur
- exit
- cease
- abort

Parameters:

tymth (closure): function wrapper closure returned by Tymist.tymen()
            method. When .tymth is called it returns associated
            Tymist.tyme. Provides injected dependency on Tymist
            tyme base.
tock (float): injected initial tock value
temp (bool): True means use temporary file resources if any
opts (dict): of injected optional additional parameters
enter(*, temp=None)

Do ‘enter’ context actions. Override in subclass. Not a generator method. Set up resources. Comparable to context manager enter.

Parameters:

temp (bool | None): True means use temporary file resources if any
                    None means ignore parameter value. Use self.temp

Inject temp or self.temp into file resources here if any

exit()

Do ‘exit’ context actions. Override in subclass. Not a generator method. Clean up resources. Comparable to context manager exit. Called by finally after normal return, close, or abort. After .exit() do returns resulting in StopIteration.

recur(tyme)

Do ‘recur’ context actions. Override in subclass. Regular method that perform repetitive actions once per invocation. Assumes resource setup in .enter() and resource takedown in .exit() (see ReDoer below for example of .recur that is a generator method)

Returns completion state of recurrence actions: True means done, False means continue.

Doist provides the time value.

.recur maybe implemented by a subclass either as a non-generator method or a generator method. This stub here is as a non-generator method. The base class .do detects which type:

If non-generator .do method runs .recur method once per iteration
    until .recur returns (True)
If generator .do method runs .recur with (yield from) until .recur
    returns (see ReDoer for example of generator .recur)
property tock

tock property getter, get ._tock .tock is float desired .tyme increment in seconds

class hio.base.doing.Doist(*, name='doist', real=False, limit=None, doers=None, temp=False, **kwa)

Bases: Tymist

Doist is the root coroutine scheduler (real python generator coroutines not fake asyncio coroutines) Provides relative cycle time in seconds with .tyme property to doers it runs The relative cycle time is advanced in .tock size increments by the by the .tick method. The doist may treat .tyme as artificial time or synchonize it to real time.

To run a Doist instance doist = Doist() in normal operation either call doist() or doist.do(). The doist instance is a callable and its .__call__ method normally calls .do()

Using asyncio: To run a Doist instance doist inside an asyncio event loop or runner then call doist.ado() which returns an asyncio coroutine object suitable for running inside an asyncio event loop runner.

For example asyncio.run(doist.ado()). The major difference between .do() and .ado() is that .ado is defined with async def so it can use await inside. Notably .do uses time.sleep, while .ado uses await asyncio.sleep().

A doist instance running in an asyncio event loop does not directly execute async coroutines as Doers. But regular Doers may themselves execute asyncio coroutines defined with async def by emulating an await using the async coroutine objects .send() method. Usually this can be wrapped try: except: that catches the StopIteraction

Example:

async def acorf():
    return True

# emulate await when not inside an async def
acoro = acorf()  # create coroutine object from async def function
try:
    acoro.send(None)  # iterate acoro using its .send method
except StopIteration as ex:
    result = ex.value  # get final returned value from acoro
    assert result == True

Usage:

- enter method prepares deeds deque of triples (dog, retyme, doer) where
    dog is a doer generator returned by calling doer generator instances,
    functions, or methods.

- recur method runs its deeds deque of triples (dog, retyme, doer) once
    per invocation. This synchronizes their cycle time .tyme to the Doist's
    tyme.

- do method repeatedly runs .recur until generators are complete. It may
    either repeat as fast as possbile or repeat at real time increments.

Inherited Class Attributes:

- Tock provides default value for .tock

Inherited Attributes:

None

Attributes:

name (str): unique identifier of doist uses for identifying resources of
            doists running in child processes in multiprocessing
real (bool): True means run in real time, Otherwise as fast as possible.
limit (float):  maximum run tyme limit then closes all doers
done (bool | None): True means completed due to limit or all deeds completed
        False is forced complete due to error
doers (list): Doer class instances, generator methods or
        function callables with attributes tock, done, and opts dict().
        Used throughout the execution lifecycle.
deeds (deque): Tuples of form (dog, retyme, doer). Where:
    dog is generator created by doer
    retyme is tyme (real or simulated) in seconds when dog should run next
    doer is associated doer in .doers list used to assign its .done state
        given completion state of its dog
    Used throughout the execution lifecycle. The normal
    case is use the default empty initialization performed here and
    update in .enter().
timer (MonoTimer): for real time intervals
temp (bool): True means use temp resources such as file path.
             When True inject into doer enters when True.
             Otherwise do not inject into doer enters.

Inherited Properties:

tyme: (float): starting relative cycle time, .tyme is artificial time
tock (float | None): float tyme lag of .tick(). None means asap

Properties:

None

Inherited Methods:

- tick(): increments .tyme by one .tock or provided tock

Methods:

- do: repeadedly call .recur until all dogs in deeds are complete or
    times out do to reaching time limit. Calls .enter., .recur, .exit
- ado: async def version of .do
- enter: prepare deeds, deque of triples (dog, retyme, doer)
- recur: run through all deeds once each invocaton of .recur
- exit: cleanly exit doers upon exception
- extend: cleanly add more doers at runtime
- remove: cleanly remove some or all doers at runtime
__init__(*, name='doist', real=False, limit=None, doers=None, temp=False, **kwa)

Returns:

instance

Inherited Parameters:

tyme (float): initial value of cycle time in seconds
tock (float | None): lag tyme in seconds between runs, None means run ASAP

Parameters:

name (str): unique identifier of doist to manage resources
real (boolean): True means run in real time,
                Otherwise run faster than real
limit (float): seconds for max run time of doist. None means no limit.
doers (iterable): Doer class instances, generator methods or
    function callables with attributes tock, done, and opts dict()
    used to initialize .doers.
    The .doers attribute is used throughout the execution lifecycle.
    Parameterization elsewhere of doers enables some special cases.
    The normal case is to initialize here or in .do().
temp (bool): True means use temp resources such as file path, inject
             into doers when True. Otherwise do not inject.
async ado(doers=None, limit=None, tyme=None, *, temp=None)

Main asyncio coroutine function. Calling returns asyncio coroutine Uses asyncio.sleep() instead of time.sleep as well as replacing real time computation using asyncio.get_event_loop().time()

See .do method for call signature

do(doers=None, limit=None, tyme=None, *, temp=None)

Main do loop. Not a generator. Readys deeds deque from .doers or doers if any and then iteratively runs .recur over deeds deque until completion of all deeds. Each entry in deeds is a triple (dog, retyme, doer) where:

dog is generator retyme is tyme (real or simulated) in seconds when dog should run next doer is from .doers list used to assign its .done state given associated completion state of its dog

If interrupted by exception call .close on each dog to force exit context.

Keyboard interrupt (cntl-c) forces exit.

Once finally clause closes a generator it must be reinited before it can be run again

Parameters:

doers (iterable): generator method or function callables with attributes
    tock, done, and opts dict(). This may be used to update the .doers
    attribute which is used throughout the execution lifecycle.
    If not provided uses .doers.
    Parameterization here of doers enables some special cases.
    The normal case is to initialize in .__init__ or here.
limit (float): is real time limit on execution. Forces close of all dogs.
tyme (float): is optional starting tyme. Resets .tyme to tyme when provided.
    If not provided uses current .tyme
temp (bool): True means use temp resources such as file path, inject
    into doers when True. Otherwise do not inject.

Returns:

None

See: https://stackoverflow.com/questions/40528867/setting-attributes-on-func For setting attributes on bound methods.

enter(doers=None, *, temp=None)

Enter context

Returns:

deeds (deque): deeds deque of triples (dog, retyme, doer) where dog is generator,
retyme is tyme (real or simulated) in seconds when dog should run next, and
doer is from .doers list used to assign its .done state given completion
state of its dog

Calls each generator callable (instance or function or method) in .doers to create each generator dog. Injects own tymth function closure, and generator function’s own tock, and opts.

Runs enter context of each dog by calling next(dog)

Parameters:

doers is list of generator method or function callables with attributes
    - tock is tyme increment in seconds
    - done is Boolean completion state
    - opts is dict() of optional parameters
    If not provided uses .doers.
    The normal case is to initialize in .__init__. or .do().
temp (bool | None): True means use temporary file resources if any
                    None means ignore parameter value. Use self.temp

Inject temp or self.temp into file resources here if any

Returns:

deeds deque():
    A deed is tuple of form (dog, retyme, doer). If not provided
    uses .deeds.

See: https://stackoverflow.com/questions/40528867/setting-attributes-on-func For setting attributes on bound methods.

exit(deeds=None)

Force exit each still opened deed calling .close on the dog generator which throws a GeneratorExit to the generator. This executes the close context (GeneratorExit) which then excecutes the exit context in the finally caluse. Each dogs exit is responsible for releasing resources Previously aborted or closed dogs have already exited Close any running dogs in reverse order so that enters and exits are nested pairs so that the corresponding exits appear in reverse order to their entes. This preserves nested resource dependencies. For example:

enter A,
    enter B,
        enter C,
        exit C,
    exit B,
exit A

Parameters:

deeds (deque): tuples of form (dog, retyme, doer).
    If not provided uses .deeds.
    Parameterization here of deeds enables some special cases.
extend(doers)

Extend .doers list with doers. Ready deeds from doers and extend .doers and .deeds. Edit deeds in place so not replace deque.

Parameters:

doers is list of doers to add as extension.
recur(deeds=None)

Recur once through deeds deque of tuples (triples) of form (dog, retyme, doer) and update in place

Each deed is deque of tuples of form (dog, retyme, doer) where:

dog is generator retyme is tyme (real or simulated) in seconds when dog should run next doer is from .doers list used to assign its .done state given associated completion state of its dog

Each cycle checks all generators in deeds deque and runs if retyme past. At end of cycle advances .tyme by one .tock by calling .tick()

Parameters:

deeds (deque):  tuples of form (dog, retyme, doer).
        Parameterization here of deeds enables some special cases.

The Parameterization here of deeds enables some special cases such as manual testing or iteraton. The normal case is to initialize .doers in .__init__. or .do() and to initialize .deeds in .__init__. and then update in .enter()

remove(doers)

Remove doers from .doers list and any associated deeds from .deeds deque. Force close removed deeds.

Parameters:

doers is list of doers to remove.
class hio.base.doing.ExDoer(**kwa)

Bases: Doer

ExDoer is example Doer for testing and demonstration Supports introspection with methods to record sends and yields

See Doer for inherited attributes, properties, and methods.

Attributes:

states (list): State namedtuples (tyme, context, feed, count)
count (int): iteration count
__init__(**kwa)

Initialize instance.

abort(ex)
cease()
enter(*, temp=None)

Do ‘enter’ context actions. Override in subclass. Not a generator method. Set up resources. Comparable to context manager enter.

Parameters:

temp (bool | None): True means use temporary file resources if any
                    None means ignore parameter value. Use self.temp

Inject temp or self.temp into file resources here if any

Doist or DoDoer winds its doers on enter

exit()
recur(tyme)
class hio.base.doing.ReDoer(*, tymth=None, tock=0.0, opts=None, temp=False, **kwa)

Bases: Doer

ReDoer is an example sub class whose .recur is a generator method not a plain method. Its .do method detects that its .recur is a generator method and executes it using yield from instead of just calling the method.

Inherited Attributes:

done (bool | None): completion state: True means completed
    Otherwise incomplete. Incompletion maybe due to close or abort.
opts (dict): injected options into its .do generator by scheduler
temp (bool | None): use temporary file resources if any

Inherited Properties:

tyme (float): relative cycle time of associated Tymist .tyme obtained
    via injected .tymth function wrapper closure.
tymth (closure): function wrapper closure returned by Tymist.tymen() method.
    When .tymth is called it returns associated Tymist.tyme.
    .tymth provides injected dependency on Tymist tyme base.
tock (float): desired time in seconds between runs or until next run,
         non negative, zero means run asap

Inherited Methods:

- wind: injects ._tymth dependency from associated Tymist to get its .tyme
- __call__: makes instance callable. Appears as generator function
    that returns generator
- do: is generator method that returns generator
- enter: is enter context action method
- recur: is recur context action method or generator method
- exit: is exit context method
- close: is close context method
- abort: is abort context method

Overidden Methods:

- recur

Hidden:

- _tymth is injected function wrapper closure returned by .tymen() of
   associated Tymist instance that returns Tymist .tyme. when called.
- _tock is hidden attribute for .tock property

Test Console:

****** ReDoer Test **********
ReDoer enter: temp=None in doist.enter next doer.do -> .enter
ReDoer recur before yield: tock=1.0, tyme=None, count=0 in doist.enter next doer.do enter
ReDoer recur after yield: tyme=0.0, count=1 in doist.recur send doer.do recur
ReDoer recur after yield: tyme=1.0, count=2 in doist.recur send doer.do recur
ReDoer recur after yield: tyme=2.0, count=3 in doist.recur send doer.do recur
ReDoer recur after break: tyme=2.0, count=3
enter(*, temp=None)

Do ‘enter’ context actions. Override in subclass. Not a generator method. Set up resources. Comparable to context manager enter.

Parameters:

temp (bool | None): True means use temporary file resources if any
                    None means ignore parameter value. Use self.temp

Inject temp or self.temp into file resources here if any

recur(tock=None)

Do ‘recur’ context actions as a generator method. Override in subclass.

Parameters:

tock (float|None): this doer when creating this generator in recur
    section of its .do method supplies its .tock as this method's
    tock parameter.
    Note, the doist tyme is delegated through the 'yield from'
    to the eventual target yield at the  bottom of delegation chain.
    when tock fed back to doist is None or 0.0 it indicates to
    run again ASAP (on next iteration of doist.do)

Returns:

completion (bool): completion state of recurrence actions.
    True means completed successfully
    False completed unsuccessfully

Note that “tyme” is not a parameter when recur is a generator method since doist tyme is injected by the explicit yield below. The recur method itself returns a generator so parameters to this method are to setup the generator not to be used at recur time.

Assumes resource setup in .enter() and resource takedown in .exit() (see Doer for example of .recur that is a regular method)

yield the current .tock accepts the current tyme return value is used for .done (true done false not done but ended)

For base class do:

yield from this generator recur method which runs until returns

class hio.base.doing.TryDoer(stop=3, **kwa)

Bases: Doer

TryDoer supports testing with methods to record sends and yields

Inherited Attributes:

done (bool | None): completion state:
                     True means completed Otherwise incomplete.
                     Incompletion maybe due to close or abort.
opts (dict): injected options into its .do generator by scheduler
temp (bool | None): use temporary file resources if any

Attributes:

states (list): State namedtuples (tyme, context, feed, count)
count (int): is context count
stop (int): count where doer completes

Inherited Properties:

tyme (float): relative cycle time of associated Tymist .tyme obtained
    via injected .tymth function wrapper closure.
tymth (closure): injected function wrapper closure returned by
        Tymist.tymen(). Calling tymth() returns associated Tymist.tyme.
tock (float): injected initial tock value. non negative, zero means run asap

Properties:

None

Methods:

- wind: injects ._tymth dependency from associated Tymist to get its .tyme
- __call__: makes instance callable. Appears as generator function
    that returns generator
- do: is generator method that returns generator
- enter: is enter context action method
- recur: is recur context action method or generator method
- exit: is exit context method
- close: is close context method
- abort: is abort context method
__init__(stop=3, **kwa)

Initialize instance.

Inherited Parameters:

tymist (Tymist): instance
tock (float): seconds initial value of .tock

Parameters:

stop (int): count when complete
abort(ex)
cease()
enter(*, temp=None)

Do ‘enter’ context actions. Override in subclass. Not a generator method. Set up resources. Comparable to context manager enter.

Parameters:

temp (bool | None): True means use temporary file resources if any
                    None means ignore parameter value. Use self.temp

Inject temp or self.temp into file resources here if any

exit()
recur(tyme)
hio.base.doing.bareDo(tymth=None, tock=0.0, *, temp=None, **opts)

Bare bones generator function template as example of generator function suitable for use with either doify wrapper or doize decorator. Make copy and rename for given application. Calling copied renamed function returns basic generator. Wrapping copied renamed function with doify returns yet unique wrapped copy with unique values of injected attributes and parameters and further renamed by wrapper. Decorating copied renamed function with doize returns singleton with injected parameter values.

Injected Attributes:

g.tock: tock  # default tock attributes
g.done: None  # default done state
g.temp: None  # temporary resources
g.opts: opts

Parameters:

tymth (closure): injected function wrapper closure returned by
        Tymist.tymen(). Calling tymth() returns associated Tymist.tyme.
tock (float): injected initial tock value
temp (bool): True means use temporary file resources if any
opts (dict):  injected optional additional parameters

The function comments show where the 6 equivalent contexts are performed enter, recur, clean, exit, (unforced) close, abort (forced) So context order may be: enter, recur, clean, exit enter, recur, cease, exit enter, recur, abort, exit enter, abort, exit

hio.base.doing.doify(f, *, name=None, tock=0.0, temp=None, **opts)

Returns Doist/DoDoer compatible copy, g, of converted generator function/method f. Each doify(f) invoction returns a unique copy of doified function/method f. Imbues copy, g, of converted generator function/method, f, with attributes used by Doist.enter() or DoDoer.enter(). Allows multiple instances of copy, g, of generator function/method, f, each with unique attributes.

Usage:

def f():
   pass

c = doify(f, name='c')

Parameters:

f (function): generator function
name (str): new function name for returned doified copy g. Default is to copy
    f.__name__
tock (float): default tock attribute of doified copy g
temp (bool | None): use temporay file resources if any
opts (dict): remaining parameters that becomes .opts attribute
    of doified copy g

Based on: https://stackoverflow.com/questions/972/adding-a-method-to-an-existing-object-instance

hio.base.doing.doifyExDo(tymth, tock=0.0, states=None, *, temp=None, **opts)

Example generator function for testing and demonstration. Example non-class based generator for use with doify wrapper. Calling this function returns generator. Wrapping this function with doify returns copy with unique attributes

Parameters:

tymth (closure): injected function wrapper closure returned by
        Tymist.tymen(). Calling tymth() returns associated Tymist.tyme.
tock (float): injected initial tock value
states (list): State namedtuples (tyme, context, feed, count)
temp (bool): True means use temporary file resources if any
opts (dict): injected optional additional parameters
hio.base.doing.doize(*, tock=0.0, temp=None, **opts)

Returns decorator that makes decorated generator function Doist compatible. Imbues decorated generator function with attributes used by Doist.enter() or DoDoer.enter(). Only one instance of decorated function with shared attributes is allowed.

Usage:

@doize
def f():
   pass

Parameters:

tock (float): default tock attribute of doized f
opts (dict): remaining parameters that becomes .opts attribute
    of doized f
hio.base.doing.doizeExDo(tymth, tock=0.0, states=None, *, temp=None, **opts)

Example decorated generator function for use with doize decorator. Example non-class based generator Calling this function returns generator

Parameters:

tymth (closure): injected function wrapper closure returned by
        Tymist.tymen(). Calling tymth() returns associated Tymist.tyme.
tock (float): injected initial tock value
states (list): of State namedtuples (tyme, context, feed, count)
temp (bool): True means use temporary file resources if any
opts (dict): injected optional additional parameters
hio.base.doing.tryDo(states, tymth, tock=0.0, *, temp=None, **opts)

Generator function test example non-class based generator. Calling this function returns generator:

Parameters:

tymth (closure): injected function wrapper closure returned by
        Tymist.tymen(). Calling tymth() returns associated Tymist.tyme.
tock (float): injected initial tock value
temp (bool): True means use temporary file resources if any
opts (dict): injected optional additional parameters

hio.base.tyming module

hio.core.tyming Module

class hio.base.tyming.Tymee(tymth=None, **kwa)

Bases: Mixin

Tymee has .tyme property that returns the artificial or simulated or cycle time from its referenced Tymist instance ._tymist.

Class Attributes:

Attributes:

Properties:
tyme (float or None): relative cycle time of associated Tymist which is

provided by calling .tymth function wrapper closure which is obtained from Tymist.tymen(). None means not assigned yet.

tymth (Callable or None): function wrapper closure returned by

Tymist.tymen() method. When .tymth is called it returns associated Tymist.tyme. Provides injected dependency on Tymist cycle tyme base. None means not assigned yet.

- wind

injects ._tymth dependency from associated Tymist to get its .tyme

Hidden:
_tymth is injected function wrapper closure returned by .tymen() of

associated Tymist instance that returns Tymist .tyme. when called.

__init__(tymth=None, **kwa)

Initialize instance :param tymth is injected function wrapper closure returned by .tymen() of: Tymist instance. Calling tymth() returns associated Tymist .tyme.

property tyme

tyme property getter, get ._tyme .tyme is float cycle time in seconds :returns: tyme from self.tymth() when wound else None :rtype: tyme (float or None)

property tymth

tymth property getter, get ._tymth returns own copy of tymist.tynth function wrapper closure for subsequent injection into related objects that want to be on same tymist tyme base.

wind(tymth)

Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Override in subclasses to update any dependencies on a change in tymist.tymth base

class hio.base.tyming.Tymer(duration=None, start=None, **kwa)

Bases: Tymee

Tymer class to measure cycle time given by .tyme property of Tymist instance. tyme is relative cycle time either artificial or real.

Inherited attributes and properties are documented on Tymee.

Properties:
  • duration (float): tyme duration in seconds from ._start to ._stop.

  • elapsed (float): tyme elapsed in seconds since ._start.

  • remaining (float): tyme remaining in seconds until ._stop.

  • expired (bool): True if expired (.tyme >= ._stop).

Hidden attributes: _tymth, _start, _stop.

Duration = 0.0
__init__(duration=None, start=None, **kwa)

Initialization method for instance. :param duration is float tymer duration in seconds: :type duration is float tymer duration in seconds: fractional :param start is float optional timer start time in seconds. Allows starting: before or after current .tyme

property duration

duration property getter, .duration = ._stop - ._start .duration is float duration tyme

property elapsed

elapsed tyme property getter, Returns elapsed tyme in seconds (fractional) since ._start.

property expired

Returns True if tymer has expired, False otherwise. .tyme >= ._stop,

property remaining

remaining tyme property getter, Returns remaining tyme in seconds (fractional) before ._stop.

restart(duration=None)

Lossless restart of Tymer at .tyme = ._stop for duration if provided, current duration otherwise No time lost. Useful to extend Tymer so no time lost

start(duration=None, start=None)

Starts Tymer of duration secs at start time start secs. If duration not provided then uses current duration. If start not provided then starts at current .tyme.

wind(tymth)

Inject new ._tymist and any other bundled tymee references Update any dependencies on a change in ._tymist by restarting at the new ._tymist time.

class hio.base.tyming.Tymist(tyme=0.0, tock=None, **kwa)

Bases: Mixin

Tymist keeps artificial or simulated or cycle time, called tyme. Provides relative cycle time, tyme, in seconds with .tyme property in incremets of .tock seconds. .tyme is advanced one .tock increment with .tick method. .tyme may be synchronized with real time by a .tyme manager

Class Attributes:

Tock: default .tock

Attributes:

Properties:

tyme: float relative cycle time, .tyme is artificial time tock: float tyme increment of .tick()

tick method increments .tyme by one .tock or provided tock
Tock = 0.03125
__init__(tyme=0.0, tock=None, **kwa)

Initialize instance :param tyme is initial value of float cycle time in seconds: :param tock is float tock time in seconds:

tick(tock=None)

Advance cycle time .tyme by tock seconds when provided othewise by .tock and return new .tyme :param tock is float of amount of time in seconds to change .tyme:

property tock

tock property getter, get ._tock .tock is float cycle time .tyme increment in seconds

property tyme

tyme property getter, get ._tyme .tyme is float cycle time in seconds

tymen()

Returns function wrapper closure tymth, when called tymth() returns .tyme. This enables read only injection of .tyme into any object via tymth() that wants to be on or access this Tymist’s tyme base.

Module contents

hio.base Package