Repository navigation
Python threading event wait influenced by date change #79928
Description
Activity
Happen on ubuntu
Opening two threads - one thread alternate system date
The seconds waits for 60 seconds. joining both threads.The execution should take at least 60 seconds. Takes less then 15 seconds.
Any work around?
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jan 15, 2019 Python 3 uses a monotonic clock to implement timeouts, such clock is not affected by system clock changes *on purpose*. See time.monotonic() and PEP-418:
https://docs.python.org/dev/library/time.html#time.monotonic
https://www.python.org/dev/peps/pep-0418/Relying on the system clock can cause severe bugs.
I suggest to close this issue as "not a bug".
thanks for the comment
please look at the code.
i use wait on event for 60 seconds.
the wait timed out in less than 60 seconds...why this is not a bug?
I think this is becase at the end, the threading code calls
sem_timedwait(thelock, &ts) where &ts is the timespect structure. The manpage of sem_timedwait says:
...
The timeout shall expire when the absolute time specified by abs_timeout passes, as measured by the clock on which timeouts are based (that is, when the value of that clock equals or exceeds abs_timeout), or if the absolute time specified by abs_timeout has already been passed at the time of the call.
If the Timers option is supported, the timeout shall be based on the CLOCK_REALTIME clock. If the Timers option is not supported, the timeout shall be based on the system clock as returned by the time() function. The resolution of the timeout shall be the resolution of the clock on which it is based. The timespec data type is defined as a structure in the <time.h> header.
So I assume this is using the system clock, so is affected by the date.
thanks @pablogsal.
looks like duplicate of bugs.python.org/issue23428
It seems like i cant trust the threading wait function and need to use busy waiting.
Oops, I posted the following comment on the wrong issue... I wanted to post the following comment on this issue!
I'm sorrry, I read the issue too quickly and misunderstood it. I guess that it's a duplicate of bpo-23428: "Use the monotonic clock for thread conditions on POSIX platforms". This issue is blocked the libc...
looks like duplicate of bugs.python.org/issue23428
Yes. I close this issue as a duplicate of bpo-23428. Let's discuss the bug there!
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:
bugs.python.org fields: