GithubHelp home page GithubHelp logo

nolar / looptime Goto Github PK

View Code? Open in Web Editor NEW
27.0 1.0 0.0 31 KB

Time dilation & contraction in asyncio event loops (in tests)

License: MIT License

Python 100.00%
pytest pytest-plugin pytest-fixtures asyncio asyncio-loop time chronometer chronograph timer clock

looptime's Introduction

looptime's People

Contributors

nolar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

looptime's Issues

Is it possible to affect an entire python process with looptime.

For our use case we need to speed up an entire python process using an event loop architecture. Would it be possible to use looptime to speed up the entire process?

Willing to put some work into making this possible, would really appreciate being pointed in the right direction.

Bug: TimerHandle.when() isn't properly mocked?

Long story short

It seems that possibly TimerHandle#when isn't properly mocked? I'm trying to write a reschedulable timer, so that if you try to rescheduled it for shorter than the original request it fails, but you can easily extend it. This code was failing and adding some logging reveals very unexpected results around the timing values.

Description

Code in question:

def resuspend_keys(timeout):
    if is_suspended():
        loop = asyncio.get_event_loop()
        until_wake = _suspend_timer.when() - loop.time()
        if timeout < until_wake:
            return

    _suspend_timer.cancel()
    suspend_keys(timeout)

IE: find the currently planned execution time, how far into the future it is... and reschedule (or not depending)... but in logging both timer.when() and loop.time() I get output like:

(--) when 1945811.476378708
(--) loop time 2.0
(--) 1945809.476378708 until wake

It looks like loop time is being mocked as the tests moved thru time (I have a await asyncio.sleep(2)) but that the when() call is still returning some actual timestamp from the live running system.

If you need any additional details, please ask.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.