8000 Failure to initialize halts/crashes your program · Issue #1534 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Failure to initialize halts/crashes your program #1534

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
phxnsharp opened this issue Aug 27, 2021 · 4 comments
Closed

Failure to initialize halts/crashes your program #1534

phxnsharp opened this issue Aug 27, 2021 · 4 comments

Comments

@phxnsharp
Copy link

Environment

  • Pythonnet version: 3.0.0-preview2021-08-03
  • Python version: 3.6.8
  • Operating System: Windows 10
  • .NET Runtime: Framework 4.6.2

Details

  • Describe what you were trying to get done.

    Start using Python from a .NET application

  • What commands did you run to trigger this issue? If you can provide a
    Minimal, Complete, and Verifiable example
    this will help us understand the issue.

If your PYTHONHOME or PYTHONPATH information is incorrect, your program will just suddenly not be running. No exceptions are raised or presented to the .NET code. This is non-starter for us. Our program is a long-lived process that might at times need to call into custom Python code written by our users. The user must be able to control the PYTHONHOME and PYTHONPATH. If they get this configuration wrong, the program appears to dump some information to the console, and then the whole program exits.

try
{
         Runtime.PythonDLL = Path.Combine(libDir, "python36.dll");
         PythonEngine.PythonPath = Path.Combine(libDir, "python-modules");
         PythonEngine.PythonHome = Path.Combine(libDir, "python3.6");
         PythonEngine.Initialize(); //Program stops running here
}
catch ( Exception e )
{
        // this exception handler is never reached
}
  • If there was a crash, please include the traceback here.

None is given. The program just suddenly exits. The debug console shows:

The program '[12004] TestProgram.exe' has exited with code -1073740791 (0xc0000409).
@phxnsharp
Copy link
Author

Similar to #1478, but this issue is specifically about the fact that the program crashes out from underneath you. I need to display an error to the user and let them continue working.

@lostmsu
Copy link
Member
lostmsu commented Sep 23, 2021

This is probably impossible to fix from our side, as the termination is initiated by Python.

You could try to spawn a subprocess with parameters specified by user to validate them by checking the exit code.

@lostmsu lostmsu closed this as completed Sep 23, 2021
@phxnsharp
Copy link
Author

@lostmsu thank you for your response. I certainly understand your point and would probably do the same myself. I'd like to submit this issue to CPython, but as Python.net intends to be an abstraction layer to hide the CPython internals from the .NET developer it is unclear exactly what internal APIs of CPython it is using to initialize.

As an aside, it seems like having a better error reporting mechanism would be beneficial Python.net. If instead of just crashing underneath you an explicit error were returned users might be able to self-solve issues like #1478 without needing to submit support issues.

Would you be able to at least point me at the specific call into the CPython API that is ultimately failing? If not, I understand. Thank you again for the great project!

@lostmsu
Copy link
Member
lostmsu commented Sep 28, 2021

@phxnsharp some exceptions can not be handled in .NET, including pretty much anything Python initialization process might raise. Your repro code pretty much demonstrates that.

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
0