-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multithreading Issue #19
Comments
For reference, I have this solved using # testing.nim
import nimpy
proc multiplier*(a: int, b: int): int {.exportpy.} =
var x = 0
echo a, " ", b
# noop to check CPU usage
for i in 0..100000000000:
x = x + a + b
return a * b Python code: import multiprocessing
import testing
# square function
def square(x):
return testing.multiplier(
x,
x,
)
if __name__ == "__main__":
# multiprocessing pool object
pool = multiprocessing.Pool()
# pool object with number of element
pool = multiprocessing.Pool(processes=6)
# input list
inputs = [0, 1, 2, 3, 4]
# map the function to the list and pass
# function and input list as arguments
outputs = pool.map(square, inputs)
# Print input list
print("Input: {}".format(inputs))
# Print output list
print("Output: {}".format(outputs)) Output:
Proof it works: |
Any update on this? |
Hi @Iapetus-11, from what I understand, this doesn't affect Linux users and there's a workaround on MacOS listed above, but Windows still suffers from this I believe. Since most people will run Flask from Linux VMs or containers, hopefully this is not too big of an issue. |
Anyways, thank you for writing such a great library. If you need any help testing or need any additional information from my tests please let me know. |
True that, yeah |
@Iapetus-11, if you're interested, I've got an in-progress complete rewrite of Nimporter that I've needed someone to help test: https://github.com/Pebaz/nimporter/releases/tag/v2.0.0rc The reason I haven't merged it so far is because it diverges from the current implementation of Nimporter v1 significantly but in return, it solidifies on the original idea of Nimporter which was to make Python + Nim projects dead-simple. Basically, I'm looking for reasons why it wouldn't work. One example is that pure-Nim libraries are the easiest to implement but what about wrapping something like Raylib with Nim and exposing it to Python? Would that work given the new v2 semantics on all platforms? Also note that the platforms listed in v2 need to be added onto, I just wanted to cover Win32, MacOS, and Linux initially. |
That'd be awesome
I'm not familiar with RayLib but I do have a project which uses nimpy's raw py buffers api and several other projects that use pure nim (and nimporter) I could test with later today. |
It seems that when trying to use a Nimpy library from multiple Python threads, an error crashes the Python interpreter:
This error originates from compiled Nim code. The information I have on it so far:
sys.modules
so when another thread tries to access it it will crash with the above error.so
per thread, creating a unique Spec and Loader object and it successfully imports, but for some reason it still crashes likely due to the underlying C extension exposing the same module name (PyInit_<mod name>
)Use this Nim module as a reference for the next 2 Python examples:
Here is a code example that you can use the reproduce the problem:
Another example:
Unfortunately, it should be noted that this issue is beyond my current (2020) skillset so any assistance is appreciated if it will contribute towards a resolution.
The text was updated successfully, but these errors were encountered: