ninia / jep

Embed Python in Java
Other
1.3k stars 147 forks source link

warning: mpd_setminalloc: ignoring request to set MPD_MINALLOC a second time #419

Open Mickey0811 opened 2 years ago

Mickey0811 commented 2 years ago

I have created 10 Java threads, and I hope to create one SubInterpreter for each thread ,but the following error still occurred.,please help children

/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/python3/python3-110/Python/Modules/_decimal/libmpdec/context.c:55: warning: mpd_setminalloc: ignoring request to set MPD_MINALLOC a second time

bsteffensmeier commented 2 years ago

It looks like the decimal module is not entirely compatible with sub-interpreters. I can repeat this problem without jep using the cpython api for testing subinterpreters(code below), so I do not think this is a problem that Jep can solve. I recommend using SharedInterpreter instead of SubInterpreter for better compatibility with modules that aren't working with sub-interpreters.

import _testcapi

_testcapi.run_in_subinterp("import decimal")
_testcapi.run_in_subinterp("import decimal")
_testcapi.run_in_subinterp("import decimal")
Mickey0811 commented 2 years ago

I want to create multiple threads, and each thread creates a sharedinterpreter, and then use these threads to execute the same method of Python at the same time, but I feel that the efficiency is not good, and the actual effect is the same as the serial execution of these sharedinterpreters. How is this going on? Is there any way to make multiple threads process the same Python method at the same time

bsteffensmeier commented 2 years ago

You may be running into the Global Interpreter Lock(GIL). More information about Jep and the GIL is on the wiki.

Mickey0811 commented 2 years ago

Can I use multiple processes to process the same function to make full use of the multi-core resources of the computer However, when I create a multi process to call the specified function in the python file and execute the python method through JEP, the following error will be reported

‘’‘ UserWarning: resource_tracker: process died unexpectedly, relaunching. Some resources might leak. warnings.warn('resource_tracker: process died unexpectedly, ' Unrecognized option: -c Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. ’‘’

What is the reason for this

bsteffensmeier commented 2 years ago

I am not sure if the multiprocessing module works with jep. It looks like your current problem is that the multiprocessing library is trying to start a java process instead of a python process. Calling multiprocessing.set_executable should help you overcome that particular problem.