Skip to content

Instantly share code, notes, and snippets.

@Roffild
Created May 22, 2019 00:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Roffild/bbe833354da6f70a3395bc13b25bff60 to your computer and use it in GitHub Desktop.
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