Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Getting an error when calling load more than once #2078

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

Closed
bendhayer opened this issue Jan 17, 2023 · 1 comment
Closed

Getting an error when calling load more than once #2078

bendhayer opened this issue Jan 17, 2023 · 1 comment
Labels
Milestone

Comments

@bendhayer
Copy link

Environment

  • Pythonnet version: 3.0.1
  • Python version: 3.11.1
  • Operating System: Windows & Linux
  • .NET Runtime: net6.0, net7.0

Details

  • Describe what you were trying to get done.

I have 2 libraries that are packaging some C# code with pythonnet as a dependency so that they can be used from Python without issues. In both libraries I call load("coreclr") in the __init__.py. When a user try to load both libraries at the same time pythonnet throw an exception. It wasn't happening with pythonnet version 2 so I suspect that this is a bug of pythonnet version 3.

from pythonnet import load

load("coreclr")
load("coreclr")
  • If there was a crash, please include the traceback here.
Failed to initialize pythonnet: System.InvalidOperationException: This property must be set before runtime is initialized
   at Python.Runtime.Runtime.set_PythonDLL(String value) in /tmp/build-via-sdist-dq4gmg3h/pythonnet-3.0.1/src/runtime/Runtime.cs:line 27
   at Python.Runtime.Loader.Initialize(IntPtr data, Int32 size) in /tmp/build-via-sdist-dq4gmg3h/pythonnet-3.0.1/src/runtime/Loader.cs:line 23
   at Python.Runtime.Runtime.set_PythonDLL(String value) in /tmp/build-via-sdist-dq4gmg3h/pythonnet-3.0.1/src/runtime/Runtime.cs:line 27
   at Python.Runtime.Loader.Initialize(IntPtr data, Int32 size) in /tmp/build-via-sdist-dq4gmg3h/pythonnet-3.0.1/src/runtime/Loader.cs:line 23Traceback (most recent call last):
  File "/home/gitlab-runner/test_pythonnet/test.py", line 4, in <module>
    load("coreclr")
  File "/home/gitlab-runner/test_pythonnet/.venv/lib/python3.11/site-packages/pythonnet/__init__.py", line 144, in load
    raise RuntimeError("Failed to initialize Python.Runtime.dll")
RuntimeError: Failed to initialize Python.Runtime.dll
filmor added a commit that referenced this issue Jan 17, 2023
@filmor
Copy link
Member

filmor commented Jan 17, 2023

This is indeed an oversight, I apparently dropped a _LOADED = True while moving code around in pythonnet.load which "allows" it to reinitialize things twice.

@filmor filmor added the bug label Jan 17, 2023
@filmor filmor added this to the 3.0.2 milestone Jan 17, 2023
filmor added a commit that referenced this issue Jan 17, 2023
filmor added a commit that referenced this issue Jan 18, 2023
@filmor filmor closed this as completed in a041811 Jan 18, 2023
elan-ajain pushed a commit to elancapital/pythonnet that referenced this issue Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants