Skip to content
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

Cannot Call Pure Function From Multiple Threads #179

Closed
Pebaz opened this issue Oct 26, 2020 · 2 comments
Closed

Cannot Call Pure Function From Multiple Threads #179

Pebaz opened this issue Oct 26, 2020 · 2 comments

Comments

@Pebaz
Copy link
Contributor

Pebaz commented Oct 26, 2020

Hello, I'm the author of Nimporter and I'm trying to debug a multithreading issue (as described here for completeness but also happens without using Nimporter).

Put simply, calling any Nim function in another thread causes Python to crash.

Reproduction Steps

calc.nim:

import nimpy

proc add(a: int, b: int): int {.exportpy.} =
    return a + b

Compiled with: nim c --threads:on --app:lib --out:calc.pyd calc

Import and use in Python file:

import threading, calc

def foo():
    print(calc.add(1, 2))

threading.Thread(target=foo).start()  # Crashes Python

Starting the second thread is what causes the crash.

@yglukhov
Copy link
Owner

Just ran it on linux, and it doesn't crash. There seems to be a typo in your code target=calc which causes python exception

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
TypeError: 'module' object is not callable

But if corrected, the program runs just fine. So it might be something windows specific.

@Pebaz
Copy link
Contributor Author

Pebaz commented Oct 26, 2020

Ah, yes sorry for the copy paste error.
That sounds familiar, now that you say that it works on Linux, I believe that there may be a Nim flag I can set for this.
Thanks for looking into it!

@Pebaz Pebaz closed this as completed Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants