Is it possible to change a dll for multiprocessing to use at runtime? /u/AwkwardBelt7105 Python Education

I’m trying to write some python code that can start up a process with multiprocessing, and that process can use a different DLL depending on what I want the process to do. So essentially swapping out the DLL at runtime. I’ve tried heaps of different methods and couldn’t find anything that worked. I tried redefining the DLL on the global scope but that didn’t work, I also tried passing the DLL through as an argument and that didn’t work as it’s not able to pickle it.

Is there any other library I could use, or should I used a different language? Or should I make the DLL an executable which can stay alive as a process and I just access a specific process depending on what I need? Like starting an executable, getting its PID and using that to access it? I’m open to pretty much any solution.

Here’s my code currently (this is a dummy example), where I tried to wrap the newly defined DLL in a new function and pass the new function in. This obviously doesn’t work but just to demontrate what I’m trying to do:

from multiprocessing import Process, Pool, freeze_support import ctypes dll = ctypes.CDLL("./hello-world-x64.dll") def f(i, call_dll): print(i) call_dll() return i def main(): for i in range(10): new_dll = ctypes.CDLL("./hello-world-x64.dll") def call_dll(): print(new_dll) Process(target=f, args=(i,call_dll,)).start() if __name__ == '__main__': freeze_support() main() 

submitted by /u/AwkwardBelt7105
[link] [comments]

​r/learnpython I’m trying to write some python code that can start up a process with multiprocessing, and that process can use a different DLL depending on what I want the process to do. So essentially swapping out the DLL at runtime. I’ve tried heaps of different methods and couldn’t find anything that worked. I tried redefining the DLL on the global scope but that didn’t work, I also tried passing the DLL through as an argument and that didn’t work as it’s not able to pickle it. Is there any other library I could use, or should I used a different language? Or should I make the DLL an executable which can stay alive as a process and I just access a specific process depending on what I need? Like starting an executable, getting its PID and using that to access it? I’m open to pretty much any solution. Here’s my code currently (this is a dummy example), where I tried to wrap the newly defined DLL in a new function and pass the new function in. This obviously doesn’t work but just to demontrate what I’m trying to do: from multiprocessing import Process, Pool, freeze_support import ctypes dll = ctypes.CDLL(“./hello-world-x64.dll”) def f(i, call_dll): print(i) call_dll() return i def main(): for i in range(10): new_dll = ctypes.CDLL(“./hello-world-x64.dll”) def call_dll(): print(new_dll) Process(target=f, args=(i,call_dll,)).start() if __name__ == ‘__main__’: freeze_support() main() submitted by /u/AwkwardBelt7105 [link] [comments] 

I’m trying to write some python code that can start up a process with multiprocessing, and that process can use a different DLL depending on what I want the process to do. So essentially swapping out the DLL at runtime. I’ve tried heaps of different methods and couldn’t find anything that worked. I tried redefining the DLL on the global scope but that didn’t work, I also tried passing the DLL through as an argument and that didn’t work as it’s not able to pickle it.

Is there any other library I could use, or should I used a different language? Or should I make the DLL an executable which can stay alive as a process and I just access a specific process depending on what I need? Like starting an executable, getting its PID and using that to access it? I’m open to pretty much any solution.

Here’s my code currently (this is a dummy example), where I tried to wrap the newly defined DLL in a new function and pass the new function in. This obviously doesn’t work but just to demontrate what I’m trying to do:

from multiprocessing import Process, Pool, freeze_support import ctypes dll = ctypes.CDLL("./hello-world-x64.dll") def f(i, call_dll): print(i) call_dll() return i def main(): for i in range(10): new_dll = ctypes.CDLL("./hello-world-x64.dll") def call_dll(): print(new_dll) Process(target=f, args=(i,call_dll,)).start() if __name__ == '__main__': freeze_support() main() 

submitted by /u/AwkwardBelt7105
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *