- Notifications
You must be signed in to change notification settings - Fork749
Closed
Description
Environment
- Pythonnet version: 2.3.0 py35
- Python version: 3.5.4
- Operating System: Windows 10
Details
I want to run this code on my Unity project:
usingPython.Runtime;usingUnityEngine;publicclassTestLib:MonoBehaviour{// Use this for initializationprivatevoidStart(){print("initializing python");PythonEngine.Initialize();print("running python code");using(Py.GIL()){dynamicnp=Py.Import("numpy");print(np.cos(np.pi*2));}print("Destroying python engine");PythonEngine.Shutdown();}}
It's able to run once but when I try to run it again, Unity editor crashes.
Here's the entire process:
I open Unity. Inside it, I clickplay to run this code, it works. And then I stop, and then I run the code again, Unity crashes.
Reasoning
- I'm suspecting that it's because python is still running in the background when I stop the game session.
But I tried Initialize() and Shutdown() twice in the code and it works (if I run it once). So I think it's not shutting down issue. It's something else that I cannot figure out. - This error depends on the python code for sure. If I remove the python part and run, it would be able to run as many times as I want.
- It might also be a threading issue which I don't understand.
What are the possible causes and fixes?
Metadata
Metadata
Assignees
Labels
No labels