44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
#PlChat is a pleroma chat client
|
|
# Copyright (C) 2021 Knott Eye
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
import os, time, platform
|
|
from ctypes import cdll, util
|
|
|
|
try:
|
|
if platform.system() == "Windows":
|
|
libc_path = "kernel32"
|
|
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
|
|
elif libc_path == "libSystem.dylib":
|
|
sleep = posixsleep
|
|
else:
|
|
print("Couldn't figure out how to use native sleep calls with "+str(libc_path)+", event loop performance may suffer.")
|
|
sleep = time.sleep |