9
9
from ctypes import cdll , c_int , c_char_p , c_ushort , c_void_p , CFUNCTYPE , \
10
10
POINTER , pointer , Structure , Union , byref
11
11
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
+
12
19
AP_DEST_HOST = 0
13
20
AP_DEST_FD = 1
14
21
@@ -37,7 +44,26 @@ class asyncproxy_ctor_args(Structure):
37
44
38
45
_asp_data_cb = CFUNCTYPE (None , c_void_p , c_int )
39
46
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
+
41
67
_asp .asyncproxy_ctor .argtypes = [POINTER (asyncproxy_ctor_args )]
42
68
_asp .asyncproxy_ctor .restype = c_void_p
43
69
_asp .asyncproxy_start .argtypes = [c_void_p ,]
@@ -168,4 +194,4 @@ def __init__(self, fd1:int, fd2:int):
168
194
args = getnull ()
169
195
a = AsyncProxy2FD (* (x .fileno () for x in args ))
170
196
a .start ()
171
- a .join (shutdown = False )
197
+ a .join (shutdown = False )
0 commit comments