forked from Supervisor/supervisor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use monotonic time for process state tracking
This makes sure system time changes (e.g. via ntp) doesn't result in odd assertion failures due to processes entering the running state before being started. Supervisor#281 Supervisor#468 https://bugs.activestate.com/show_bug.cgi?id=104508 https://activestate.atlassian.net/browse/STO-859
- Loading branch information
Mark Yen
committed
Jul 22, 2014
1 parent
0e53f90
commit aab77f4
Showing
4 changed files
with
49 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from __future__ import absolute_import | ||
|
||
import sys | ||
|
||
try: # pragma: no cover | ||
from time import monotonic as monotonic_time | ||
except ImportError: # pragma: no cover | ||
if sys.platform == "linux2": | ||
# Adapted from http://stackoverflow.com/questions/1205722/ | ||
import ctypes | ||
import os | ||
CLOCK_MONOTONIC_RAW = 4 # see <linux/time.h> | ||
|
||
class timespec(ctypes.Structure): | ||
_fields_ = [ | ||
('tv_sec', ctypes.c_long), | ||
('tv_nsec', ctypes.c_long) | ||
] | ||
librt = ctypes.CDLL('librt.so.1', use_errno=True) | ||
clock_gettime = librt.clock_gettime | ||
clock_gettime.argtypes = [ctypes.c_int32, ctypes.POINTER(timespec)] | ||
|
||
def monotonic_time(): | ||
t = timespec() | ||
if clock_gettime(CLOCK_MONOTONIC_RAW, ctypes.pointer(t)) != 0: | ||
errno_ = ctypes.get_errno() | ||
raise OSError(errno_, os.strerror(errno_)) | ||
return t.tv_sec + t.tv_nsec * 1e-9 | ||
else: | ||
from time import monotonic # raises ImportError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters