Content-Length: 277116 | pFad | http://github.com/RustPython/RustPython/issues/5690

89 Panic when using Windows GUI app · Issue #5690 · RustPython/RustPython · GitHub
Skip to content

Panic when using Windows GUI app #5690

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

Open
marcomq opened this issue Apr 11, 2025 · 5 comments
Open

Panic when using Windows GUI app #5690

marcomq opened this issue Apr 11, 2025 · 5 comments
Labels
C-bug Something isn't working

Comments

@marcomq
Copy link

marcomq commented Apr 11, 2025

Summary

I tried to use RustPython in a windows GUI app, so that python code is running in the background and the result is displayed in a GUI. Unfortunately, it seems that stdin/stdout is required. I get a essential initialization failed panic error

 Error in sys.excepthook:
lost sys.stderr
RuntimeError: lost sys.stderr
Original exception was:
lost sys.stderr
OSError: (9, 'Das Handle ist ungültig. (os error 6)')

thread 'main' panicked at C:\Users\MyUser\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rustpython-vm-0.4.0\src\vm\mod.rs:334:30:
essential initialization failed

I also have a sample tauri application here that can replicate the issue:
https://github.com/marcomq/tauri-plugin-python/tree/main/examples/plain-javascript

The gui is preventing the console with

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

I could also uncomment this line, but this would then always show a console in the background of the windows app, which is kind of a very ugly workaround.
I will check if I can maybe fix it locally, but I just wanted to create this issue first for documentation.

Expected

It would be nice if it wouldn't be required to have a console, similar to wasm/wasi mode.

Actual

The issue can only be replicated on windows release without console, so there is probably no real error visible and the application just doesn't start up.

Python Documentation

@marcomq marcomq added the C-bug Something isn't working label Apr 11, 2025
@youknowone
Copy link
Member

optional stdio issue may be related

@marcomq
Copy link
Author

marcomq commented Apr 11, 2025

It seems that it is possible to re-enable the console for windows when performing

        use windows::Win32::System::Console::{AttachConsole, ATTACH_PARENT_PROCESS};
        let _ = unsafe { AttachConsole(ATTACH_PARENT_PROCESS) };

But unfortunately, this doesn't seem to fix the panic issue.

So I created this PR:
https://github.com/RustPython/RustPython/pull/5691/files

I also tried to just disable std::err and std::in, but this somehow didn't work and caused the same error.
I actually didn't really check where the panic was coming from. So there is probably a technically better solution out there. But the solution from PR works fine for me. Not sure if somebody actually needs more.

@youknowone
Copy link
Member

There was also #5420.

@arihant2math @coolreader18 we seem to merge one of them, right? Could you help for decision and reviews?

@arihant2math
Copy link
Collaborator

I was searching through, since I remember using println! in tauri, and found the following:
https://doc.rust-lang.org/std/io/struct.Stdout.html#note-windows-portability-considerations.

When operating in a console, the Windows implementation of this stream does not support non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return an error.

The error message is Das Handle ist ungültig. (os error 6) -- the ü from that is a non UTF-8 character which seems to be part of that error.

Also the example tauri application seems to be working for me.

Image

@arihant2math
Copy link
Collaborator

we seem to merge one of them, right? Could you help for decision and reviews?

In my opinion #5691 is slightly cleaner, but both should be essentially equivalent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/RustPython/RustPython/issues/5690

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy