Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use multiprocessing in PythonDLL
import multiprocessing
import sys
__file__ = r'path_to\multiprocessing_example.py'
sys.argv = [__file__]
python_exe = r'path_to\python.exe'
def getresult(outp):
while True:
array = outp.recv()
outp.send(array[:2])
class MQL():
def __init__(self):
self.proc = None
def getLong(self, magic: int, value: int, array: tuple) -> tuple or list:
raise NotImplementedError
def getULong(self, magic: int, value: int, array: tuple) -> tuple or list:
raise NotImplementedError
def getDouble(self, magic: int, value: float, array: tuple) -> tuple or list:
if self.proc is None:
multiprocessing.set_executable(python_exe)
(self.inp, self.outp) = multiprocessing.Pipe(True)
self.proc = multiprocessing.Process(target=getresult, args=(self.outp,))
self.proc.daemon = True
self.proc.start()
self.inp.send(array)
ret = self.inp.recv()
print(ret)
return ret
def getString(self, magic: int, value: str, array: bytes) -> str:
raise NotImplementedError
__mql__ = MQL()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment