[openstack-dev] time.sleep is affected by eventlet.monkey_patch()
victor stinner
victor.stinner at enovance.com
Fri Mar 7 11:43:03 UTC 2014
Hi,
Yes, a monotonic *must* be used to compute timeouts. I wrote the time.monotonic() function of Python 3.3 and the PEP 418. For my Trollius project, I wrote this code for Python 2 using ctypes. It works on Linux, Windows, Mac OS X, OpenBSD, FreeBSD and Solaris:
https://bitbucket.org/enovance/trollius/src/5e45fc18fce0b34a47481916a274dace7f2964f4/asyncio/time_monotonic.py?at=trollius
There are existing Python modules, examples:
https://github.com/gavinbeatty/python-monotonic-time
https://github.com/ludios/Monoclock
Any other many projecs have their own implementation.
Read also the 418 for the background:
http://legacy.python.org/dev/peps/pep-0418/
FYI On Linux, since the glibc 2.17, clock_gettime() is provided by the libc. On older glibc versions, it is provided by librt.
Victor
----- Mail original -----
> De: "Yuriy Taraday" <yorik.sar at gmail.com>
> À: "OpenStack Development Mailing List (not for usage questions)" <openstack-dev at lists.openstack.org>
> Envoyé: Vendredi 7 Mars 2014 08:52:56
> Objet: Re: [openstack-dev] time.sleep is affected by eventlet.monkey_patch()
>
> On Fri, Mar 7, 2014 at 11:20 AM, Yuriy Taraday < yorik.sar at gmail.com > wrote:
>
>
>
> All in all it sounds like an eventlet bug. I'm not sure how it can be dealt
> with though.
>
> Digging into it I found out that eventlet uses time.time() by default that is
> not monotonic. There's no clear way to replace it, but you can workaround
> this:
> 1. Get monotonic clock function here:
> http://stackoverflow.com/a/1205762/238308 (note that for FreeBSD or MacOS
> you'll have to use different constant).
> 2. Make eventlet's hub use it:
> eventlet.hubs._threadlocal.hub =
> eventlet.hubs.get_default_hub().Hub(monotonic_time)
>
> --
>
> Kind regards, Yuriy.
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
More information about the OpenStack-dev
mailing list