You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2012-06-04.23:09:50.912>created_at=<Date2012-03-28.01:11:31.262>labels= ['type-feature', 'library']
title='Implementation of the PEP 418'updated_at=<Date2012-06-05.17:28:52.432>user='https://github.com/vstinner'
Attached patch implements the PEP-418: add time.monotonic() and time.hires(). In practice, it replaces time.steady() by time.hires() and time.steady(strict=True) by time.monotonic().
since it's relatively straightforward to cache the last value returned using a static variable, it might be interesting to use this to make sure that the values returned are indeed monotonic
I think you need to reconsider the time.steady() name you're using
in the PEP. For practical purposes, it's better to call it
time.monotonic() and only make the function available if the OS provides
a monotonic clock.
The fallback to time.time() is not a good idea, since then the programmer
has to check whether the timer really provides the features she's after
every time it gets used.
Regardless of this functional problem, I'm also not sure what you want
to imply by the term "steady". A steady beat would mean that the timer
never stops and keeps a constant pace, but that's not the case for
the timers you're using to implement time.steady(). If you're after
a mathematical term, "continuous" would be a better term, but
again, time.time() is not always continuous.
Instead of trying to tweak all the different clocks and timers into
a single function, wouldn't it be better to expose each kind as a
different function and then let the programmer decide which fits
best ?!
BTW: Thanks for the research you've done on the different clocks and
timers. That's very useful information.
Thanks,
Marc-Andre Lemburg
eGenix.com
2012-04-03: Python Meeting Duesseldorf today
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/
I think you need to reconsider the time.steady() name you're using
in the PEP. For practical purposes, it's better to call it
time.monotonic()
I opened a new thread on python-dev to discuss this topic.
and only make the function available if the OS provides
a monotonic clock.
Oh, I should explain this choice in the PEP. Basically, the idea is to
provide a best-effort portable function.
The fallback to time.time() is not a good idea, since then the programmer
has to check whether the timer really provides the features she's after
every time it gets used.
Nope, time.get_clock_info('steady') does not change at runtime. So it
can only be checked once.
Instead of trying to tweak all the different clocks and timers into
a single function, wouldn't it be better to expose each kind as a
different function and then let the programmer decide which fits
best ?!
This is a completly different approach. It should be discussed on
python-dev, not in the bug tracker please. I think that Python can
help the developer to write portable code by providing high-level
functions because clock properties are well known (e.g. see
time.get_clock_info).
BTW: Thanks for the research you've done on the different clocks and
timers. That's very useful information.
> I think you need to reconsider the time.steady() name you're using
> in the PEP. For practical purposes, it's better to call it
> time.monotonic()
I opened a new thread on python-dev to discuss this topic.
> and only make the function available if the OS provides
> a monotonic clock.
Oh, I should explain this choice in the PEP. Basically, the idea is to
provide a best-effort portable function.
> The fallback to time.time() is not a good idea, since then the programmer
> has to check whether the timer really provides the features she's after
> every time it gets used.
Nope, time.get_clock_info('steady') does not change at runtime. So it
can only be checked once.
With "every time" I meant: in every application you use the function.
That pretty much spoils the idea of a best effort portable function.
It's better to use a try-except to test for availability of
functions than to have to (remember to) call a separate function
to find out the characteristics of the best effort approach.
> Instead of trying to tweak all the different clocks and timers into
> a single function, wouldn't it be better to expose each kind as a
> different function and then let the programmer decide which fits
> best ?!
This is a completly different approach. It should be discussed on
python-dev, not in the bug tracker please. I think that Python can
help the developer to write portable code by providing high-level
functions because clock properties are well known (e.g. see
time.get_clock_info).
Fair enough.
BTW: Are aware of the existing systimes.py module in pybench,
which already provides interfaces to high resolution timers usable
for benchmarking in a portable way ? Perhaps worth mentioning in
the PEP.
BTW: Are aware of the existing systimes.py module in pybench,
which already provides interfaces to high resolution timers usable
for benchmarking in a portable way ? Perhaps worth mentioning in
the PEP.
Nope, I didn't know it. It mentioned it in the PEP.
"The test is a bit too optimistic: a thread is looping for 0.2s, and the test checks that the process time (user + system) increased of at least 0.1s. If the thread is preempted, there's a high chance you won't get even as low as 0.1s."
Hum, the problem is maybe that the thread is preempted, but the first problem is that the test considers that time.process_time() uses seconds.
I rewrote the test to make it more reliable.
neologix commented on Apr 29, 2012
neologixmannequin
Mannequin
More actions
Hum, the problem is maybe that the thread is preempted, but the first
problem is that the test considers that time.process_time() uses seconds.
Hum, what?
You mean that process_time() doesn't return seconds?
Traceback (most recent call last):
File "/usr/home/buildbot/buildarea/3.x.krah-freebsd/build/Lib/test/test_time.py", line 441, in test_process_time_threadsself.assertGreaterEqual(t2 - t1, busy)
AssertionError: 0.01249799999999368 not greater than or equal to 0.013093999999966854
I see two options: either increase the total running time,
to make it really likely you'll get a chance to run
(or decrase the lower threshold), or use times(2), and
check the result against that (does Windows have such a syscall?).
I wrote the test to check if time.process_time() measures the total CPU of the process, and not the CPU time of only the current thread.
I'm tired of this PEP, so I just removed the test. I don't think that it is really interesting and it looks difficult to write a reliable test.
neologix commented on Apr 30, 2012
neologixmannequin
Mannequin
More actions
Yes, dt is not a number of seconds in the following example:
It really looks like seconds to me, definitely not jiffies ;-)
Also, I've had a quick look at the code, and ISTM that it does indeed
return seconds.
I wrote the test to check if time.process_time() measures the total CPU of
the process, and not the CPU time of only the current thread.
I'm tired of this PEP, so I just removed the test. I don't think that it is
really interesting and it looks difficult to write a reliable test.
Hum, right now, the only process_time test I see is test_process_time,
which just checks that a sleep almost doesn't consume "process time",
which is a bit light.
"""
# Use a factor of 0.75 because time.process_time() is maybe not precise
self.assertGreaterEqual(t2 - t1, busy * 0.75)
"""
It's not that process_time() is not precise (I assume you mean accurate ;-).
It's just that since it measures CPU time (user+system), it depends on
the scheduling: in fact, if you have let's say a real-time priority
task running at the same time, on a uniprocessor system, the thread
could in theory not even get a chance to run, which would yield a CPU
time of 0: that would still be accurate.
According to Wikipedia: "Since 1967, the second has been defined to be: the duration of 9,192,631,770 periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the caesium 133 atom."
The caesium 133 atom is not sleeping while your process is sleeping, so you cannot say the time.process_time() uses second. Do you see what I mean?
@neologix: Please open a new issue if you disagree with me on the definition of "seconds" for time.process_time().
I won't reopen, but I still disagree with your definition.
process_time() returns second, as does the Unix 'time' command return:
"""
$ time sleep 1
real 0m1.014s
user 0m0.000s
sys 0m0.000s
"""
AFAICT, process_time() returns user + sys. Since the unit of those two
fields are second, the value returned is in second. I doesn't include
time spent in 'S'/'D'/whatever time, but it's still seconds.
I don't know what you two are arguing about, since the process_time() doc says "Return the value (in fractional seconds) of the sum of the system and user CPU time of the current process".
(while I'm not sure what "fractional" seconds are, they are probably seconds in the first place :-))
Activity
vstinner commentedon Mar 28, 2012
Attached patch implements the PEP-418: add time.monotonic() and time.hires(). In practice, it replaces time.steady() by time.hires() and time.steady(strict=True) by time.monotonic().
neologix commentedon Mar 28, 2012
Tiny review.
Two more details:
hiresname bothers me a bit, I'd preferhighres(see for example http://www.kernel.org/doc/Documentation/timers/highres.txt, the highres kernel parameter and patch-set name), or maybehrtimevstinner commentedon Apr 2, 2012
Updated patch:
TODO: time.monotonic() must use GetTickCount64() or GetTickCount() on Windows, with a detection of integer overflow on GetTickCount().
vstinner commentedon Apr 2, 2012
Patch version 3:
Clock information on different operating systems.
Linux (Fedora 16) on x86_64:
FreeBSD 8.2 on x86_64:
OpenBSD on x86_64:
Python 32 bits on Windows 64 bits:
Some remarks:
vstinner commentedon Apr 2, 2012
Solaris on x86_64:
vstinner commentedon Apr 2, 2012
TODO (PEP-418-3.patch):
malemburg commentedon Apr 3, 2012
Hi Victor,
I think you need to reconsider the time.steady() name you're using
in the PEP. For practical purposes, it's better to call it
time.monotonic() and only make the function available if the OS provides
a monotonic clock.
The fallback to time.time() is not a good idea, since then the programmer
has to check whether the timer really provides the features she's after
every time it gets used.
Regardless of this functional problem, I'm also not sure what you want
to imply by the term "steady". A steady beat would mean that the timer
never stops and keeps a constant pace, but that's not the case for
the timers you're using to implement time.steady(). If you're after
a mathematical term, "continuous" would be a better term, but
again, time.time() is not always continuous.
Instead of trying to tweak all the different clocks and timers into
a single function, wouldn't it be better to expose each kind as a
different function and then let the programmer decide which fits
best ?!
BTW: Thanks for the research you've done on the different clocks and
timers. That's very useful information.
Thanks,
Marc-Andre Lemburg
eGenix.com
2012-04-03: Python Meeting Duesseldorf today
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
vstinner commentedon Apr 3, 2012
I opened a new thread on python-dev to discuss this topic.
Oh, I should explain this choice in the PEP. Basically, the idea is to
provide a best-effort portable function.
Nope, time.get_clock_info('steady') does not change at runtime. So it
can only be checked once.
This is a completly different approach. It should be discussed on
python-dev, not in the bug tracker please. I think that Python can
help the developer to write portable code by providing high-level
functions because clock properties are well known (e.g. see
time.get_clock_info).
You're welcome.
malemburg commentedon Apr 3, 2012
STINNER Victor wrote:
With "every time" I meant: in every application you use the function.
That pretty much spoils the idea of a best effort portable function.
It's better to use a try-except to test for availability of
functions than to have to (remember to) call a separate function
to find out the characteristics of the best effort approach.
Fair enough.
BTW: Are aware of the existing systimes.py module in pybench,
which already provides interfaces to high resolution timers usable
for benchmarking in a portable way ? Perhaps worth mentioning in
the PEP.
vstinner commentedon Apr 3, 2012
Patch version 4:
vstinner commentedon Apr 3, 2012
Nope, I didn't know it. It mentioned it in the PEP.
vstinner commentedon Apr 4, 2012
Patch version 5, updated to the last version of the PEP:
vstinner commentedon Apr 4, 2012
+#if defined(linux) || defined(__linux) || defined(linux)
Hum, a better check should be done in configure and/or a macro like MS_WINDOWS should be added.
vstinner commentedon Apr 4, 2012
Version 6: simplify the code handling GetTickCounter() integer overflow. We don't need a has_last_ticks variable.
20 remaining items
python-dev commentedon Apr 29, 2012
New changeset 1255cac63dfc by Victor Stinner in branch 'default':
Issue bpo-14428: Rewrite test_process_time_threads() test
http://hg.python.org/cpython/rev/1255cac63dfc
vstinner commentedon Apr 29, 2012
"The test is a bit too optimistic: a thread is looping for 0.2s, and the test checks that the process time (user + system) increased of at least 0.1s. If the thread is preempted, there's a high chance you won't get even as low as 0.1s."
Hum, the problem is maybe that the thread is preempted, but the first problem is that the test considers that time.process_time() uses seconds.
I rewrote the test to make it more reliable.
neologix commentedon Apr 29, 2012
Hum, what?
You mean that process_time() doesn't return seconds?
pitrou commentedon Apr 29, 2012
There are many sporadic failures on the buildbots:
======================================================================
FAIL: test_process_time_threads (test.test_time.TimeTestCase)
----------------------------------------------------------------------
python-dev commentedon Apr 29, 2012
New changeset 0bdf0727ee29 by Victor Stinner in branch 'default':
Issue bpo-14428: Make test_process_time_threads() less strict
http://hg.python.org/cpython/rev/0bdf0727ee29
python-dev commentedon Apr 29, 2012
New changeset ad3d6010379b by Victor Stinner in branch 'default':
Issue bpo-14428: Remove test_process_time_threads() from test_time
http://hg.python.org/cpython/rev/ad3d6010379b
vstinner commentedon Apr 29, 2012
Yes, dt is not a number of seconds in the following example:
I wrote the test to check if time.process_time() measures the total CPU of the process, and not the CPU time of only the current thread.
I'm tired of this PEP, so I just removed the test. I don't think that it is really interesting and it looks difficult to write a reliable test.
neologix commentedon Apr 30, 2012
OK, so what is it then?
It's not written anywhere - neither in the PEP nor in the
documentation - and it should.
Furthermore:
"""
$ cat /tmp/test_ptime.py
import sys
import time
print("real time: %f" % (time.time() - rt))
print("process time: %f" % (time.process_time() - pt))
$ ./python /tmp/test_ptime.py 100000
real time: 0.168570
process time: 0.168425
"""
It really looks like seconds to me, definitely not jiffies ;-)
Also, I've had a quick look at the code, and ISTM that it does indeed
return seconds.
Hum, right now, the only process_time test I see is test_process_time,
which just checks that a sleep almost doesn't consume "process time",
which is a bit light.
"""
# Use a factor of 0.75 because time.process_time() is maybe not precise
self.assertGreaterEqual(t2 - t1, busy * 0.75)
"""
It's not that process_time() is not precise (I assume you mean accurate ;-).
It's just that since it measures CPU time (user+system), it depends on
the scheduling: in fact, if you have let's say a real-time priority
task running at the same time, on a uniprocessor system, the thread
could in theory not even get a chance to run, which would yield a CPU
time of 0: that would still be accurate.
vstinner commentedon May 30, 2012
time.process_time() uses maybe "seconds" on Linux, but it doesn't include time elapsed during sleep. See the test:
According to Wikipedia: "Since 1967, the second has been defined to be: the duration of 9,192,631,770 periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the caesium 133 atom."
The caesium 133 atom is not sleeping while your process is sleeping, so you cannot say the time.process_time() uses second. Do you see what I mean?
vstinner commentedon Jun 4, 2012
I'm closing again this issue.
@neologix: Please open a new issue if you disagree with me on the definition of "seconds" for time.process_time().
neologix commentedon Jun 5, 2012
I won't reopen, but I still disagree with your definition.
process_time() returns second, as does the Unix 'time' command return:
"""
$ time sleep 1
real 0m1.014s
user 0m0.000s
sys 0m0.000s
"""
AFAICT, process_time() returns user + sys. Since the unit of those two
fields are second, the value returned is in second. I doesn't include
time spent in 'S'/'D'/whatever time, but it's still seconds.
pitrou commentedon Jun 5, 2012
I don't know what you two are arguing about, since the process_time() doc says "Return the value (in fractional seconds) of the sum of the system and user CPU time of the current process".
(while I'm not sure what "fractional" seconds are, they are probably seconds in the first place :-))