I am trying to parallelize a code in python by using multiprocessing.Process which targets a Julia function.
The function works fine when I call it directly, i.e. when I execute:
if __name__ == "__main__":
import julia
julia.Julia(compiled_modules=False)
julia.Pkg_jl.func_jl(*args)
However, I have an error when I define the same function as a target in a Process function.
This is the code:
from multiprocessing import Process
import julia
julia.Julia(compiled_modules=False)
class JuliaProcess(object):
...
def _wrapper(self, *args):
ret = julia.Pkg_jl.func_jl(args)
self.queue.put(ret) # this is for save the result of the function
def run(self, *args):
p = Process(target=self._wrapper, args=args)
self.processes.append(p) # this is for save the process job
p.start()
...
if __name__ == "__main__":
...
Jlproc = JuliaProcess()
Jlproc.run(some_args)
The error is when the Process starts, with the following output:
fatal: error thrown and no exception handler available.
ReadOnlyMemoryError()
unknown function (ip: 0x7f9df81cb8f0)
...
If I try to compile the julia modules in the _wrapper function, i.e.:
from multiprocessing import Process
import julia
class JuliaProcess(object):
...
def _wrapper(self, *args):
julia.Julia(compiled_modules=False)
ret = julia.Pkg_jl.func_jl(args)
self.queue.put(ret) # this is for save the result of the function
def run(self, *args):
p = Process(target=self._wrapper, args=args)
self.processes.append(p) # this is for save the process job
p.start()
...
if __name__ == "__main__":
...
Jlproc = JuliaProcess()
Jlproc.run(some_args)
I have the following error:
raise JuliaError(u'Exception \'{}\' occurred while calling julia code:\n{}'
julia.core.JuliaError: Exception 'ReadOnlyMemoryError' occurred while calling julia code:
const PyCall = Base.require(Base.PkgId(Base.UUID("438e738f-606a-5dbb-bf0a-cddfbfd45ab0"), "PyCall"))
...
Does anyone know what is happening? and whether it is possible using python to parallelize julia functions as I suggest.