8000 Cannot run twice; Unity crashes after running more than once · Issue #701 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

10000 Skip to content
Cannot run twice; Unity crashes after running more than once #701
Closed
@offchan42

Description

@offchan42

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:

using Python.Runtime;
using UnityEngine;

public class TestLib : MonoBehaviour
{
    // Use this for initialization
    private void Start()
    {
        print("initializing python");
        PythonEngine.Initialize();
        print("running python code");
        using (Py.GIL())
        {
            dynamic np = Py.Import("numpy");
            print(np.cos(np.pi * 2));
        }

        print("Destroying python engine");
        PythonEngine.Shutdown();
    }
}

Here's the output:
2018-07-06_05-02-13

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 click play 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0