Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa09cbb

Browse files
committed
Use library compiled into a module if available.
1 parent e24c9c1 commit fa09cbb

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

python/AsyncProxy.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
from ctypes import cdll, c_int, c_char_p, c_ushort, c_void_p, CFUNCTYPE, \
1010
POINTER, pointer, Structure, Union, byref
1111

12+
from sysconfig import get_config_var
13+
from site import getsitepackages
14+
from pathlib import Path
15+
from os.path import abspath, dirname, join as path_join
16+
17+
from .env import LAP_MOD_NAME
18+
1219
AP_DEST_HOST = 0
1320
AP_DEST_FD = 1
1421

@@ -37,7 +44,26 @@ class asyncproxy_ctor_args(Structure):
3744

3845
_asp_data_cb = CFUNCTYPE(None, c_void_p, c_int)
3946

40-
_asp = cdll.LoadLibrary('libasyncproxy.so')
47+
_esuf = get_config_var('EXT_SUFFIX')
48+
if not _esuf:
49+
_esuf = '.so'
50+
try:
51+
_ROOT = str(Path(__file__).parent.absolute())
52+
except ImportError:
53+
_ROOT = abspath(dirname(__file__))
54+
#print('ROOT: ' + str(_ROOT))
55+
modloc = getsitepackages()
56+
modloc.insert(0, path_join(_ROOT, ".."))
57+
for p in modloc:
58+
try:
59+
#print("Trying %s" % path_join(p, LAP_MOD_NAME + _esuf))
60+
_asp = cdll.LoadLibrary(path_join(p, LAP_MOD_NAME + _esuf))
61+
except:
62+
continue
63+
break
64+
else:
65+
_asp = cdll.LoadLibrary('libasyncproxy.so')
66+
4167
_asp.asyncproxy_ctor.argtypes = [POINTER(asyncproxy_ctor_args)]
4268
_asp.asyncproxy_ctor.restype = c_void_p
4369
_asp.asyncproxy_start.argtypes = [c_void_p,]
@@ -168,4 +194,4 @@ def __init__(self, fd1:int, fd2:int):
168194
args = getnull()
169195
a = AsyncProxy2FD(*(x.fileno() for x in args))
170196
a.start()
171-
a.join(shutdown=False)
197+
a.join(shutdown=False)

0 commit comments

Comments
 (0)