My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python

from __future__ import division
__all__ = ["monotonic_time"]
import ctypes, os, sys

if sys.platform == "win32":
GetTickCount64 = ctypes.windll.kernel32.GetTickCount64
GetTickCount64.restype = ctypes.c_ulonglong
def monotonic_time():
return GetTickCount64() / 1000
else:
CLOCK_MONOTONIC = 1 # 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_int, ctypes.POINTER(timespec)]
def monotonic_time():
t = timespec()
if clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(t)) != 0:
errno_ = ctypes.get_errno()
raise OSError(errno_, os.strerror(errno_))
return t.tv_sec + t.tv_nsec / 1e9

if __name__ == "__main__":
print monotonic_time()

Change log

a223ecd8cc90 by Matt Joiner <anacrolix> on Jun 22, 2010   Diff
pimu:
Monotonic time on Winders.
Go to: 
Sign in to write a code review

Older revisions

ec0be05faea6 by Matt Joiner <anacrolix> on Jun 21, 2010   Diff
pimu:
Rather than prepending _, use __all__
to only export "monotonic_time".
Set window caption on client.
71ef547c8351 by Matt Joiner <anacrolix> on Jun 21, 2010   Diff
pimu:
Add module for monotonic time.
All revisions of this file

File info

Size: 876 bytes, 30 lines
Powered by Google Project Hosting