我有一些我在Python中使用的现有C代码.我可以使用以下命令加载库:
library_path = '/full/path/to/my/library.dylib'
lib1 = cdll.LoadLibrary(library_path)
Run Code Online (Sandbox Code Playgroud)
问题是我需要有这个库的多个实例,例如:
lib2 = cdll.LoadLibrary(library_path)
Run Code Online (Sandbox Code Playgroud)
这会创建第二个实例,但两者似乎都具有相同的内存位置(句柄相同).我试图复制和重命名library.dylib到library1.dylib和library2.dylib,但这并不改变他们的加载.问题是当我在lib1中调用函数时,修改了lib2中的全局变量和状态变量.例如:
lib1.open('/path/to/myfile') # open a file for processing
lib1.run() # This will do something with the file
lib2.open('/path/to/anotherfile') # open a file for processing
lib2.run() # This will do something with the file
lib1.close() # Closes library 1
lib2.run() # This fails because lib1.close() also closes lib2
Run Code Online (Sandbox Code Playgroud)
有没有办法以这些库实例保持"包含"的方式加载它们?我试图加载的C代码是非常大的遗留软件......我需要做一些重写吗?
这是我发现解决类似问题的链接,但对我没那么帮助:http://www.gossamer-threads.com/lists/python/python/826703
任何帮助是极大的赞赏.
| 归档时间: |
|
| 查看次数: |
841 次 |
| 最近记录: |