34 lines
845 B
Python
34 lines
845 B
Python
import os, time, platform
|
|
from ctypes import cdll, util
|
|
|
|
#try:
|
|
# if os.name == 'posix':
|
|
# libc = cdll.LoadLibrary("libc.so.6")
|
|
# elif os.name == 'nt':
|
|
# libc = cdll.kernel32
|
|
#except:
|
|
# libc = None
|
|
try:
|
|
if platform.system() == "Windows":
|
|
libc_path = util.find_library("msvcrt")
|
|
else:
|
|
libc_path = util.find_library("c")
|
|
libc = cdll.LoadLibrary(libc_path)
|
|
print("Loaded libc from "+libc_path)
|
|
except:
|
|
libc_path = None
|
|
libc = None
|
|
|
|
def posixsleep(t):
|
|
libc.usleep(int(t * 1000000))
|
|
|
|
def ntsleep(t):
|
|
libc.Sleep(int(t * 1000))
|
|
|
|
if libc_path == 'libc.so.6':
|
|
sleep = posixsleep
|
|
elif libc_path == 'kernel32':
|
|
sleep = ntsleep
|
|
else:
|
|
print("Couldn't figure out how to use native sleep calls with "+str(libc_path)+", event loop performance may suffer.")
|
|
sleep = time.sleep |