Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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:

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();}}

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

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp