Skip to content
This repository was archived by the owner on Nov 23, 2023. It is now read-only.
This repository was archived by the owner on Nov 23, 2023. It is now read-only.

iipyper: @repeat should provide accurate timing and warnings #11

@jarmitage

Description

@jarmitage

e.g.

def repeat(_time):
    # close the decorator over time argument
    def decorator(f):
        # define the coroutine
        async def g():
            # call `f` every `time` seconds
            while True:
                t1 = time.time()
                f()
                t2 = time.time()
                delta_t = t2 - t1
                sleep_time = _time-delta_t

                if (sleep_time < 0):
                    print("Warning: repeat@ sleep time < 0")
                    await asyncio.sleep(0)
                else:
                    await asyncio.sleep(sleep_time)

        # track the coroutine in a global list
        _loop_fns.append(g)

    return decorator

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions