2021-04-15 15:16:38 -05:00
|
|
|
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
|
2021-04-15 16:28:04 -05:00
|
|
|
elif libc_path == "libSystem.dylib":
|
|
|
|
sleep = posixsleep
|
2021-04-15 15:16:38 -05:00
|
|
|
else:
|
|
|
|
print("Couldn't figure out how to use native sleep calls with "+str(libc_path)+", event loop performance may suffer.")
|
|
|
|
sleep = time.sleep
|