pybind / pybind/pybind11

[BUG] scoped redirect is crashing on windows pythonw.exe but not python.exe

Open
#2,994 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

When binding to my C++ function with py::call_guard. I'm only able to run the function from Python on Windows when I run python.exe (with the console). It crashes when I run it with pythonw.exe (hide the console, aka for desktop apps)

m.def("my_converter", 
      &run_my_converter,
      py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>(),
      "run my_converter");

I've tested this on mac, linux, windows with python.exe, and pythonw.exe and the only problem I have had has been with windows and pythonw.exe

Edit:
I'm very sorry because this is a real pain to replicate since you can't reproduce this with console output to view the stacktrace.

Here's how I did it. I ran the pybind11 extension function in a try catch block and used a tkinter dialogbox to output the traceback.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the sample py::call_guard using py::scoped_ostream_redirect and py::scoped_estream_redirect. Reproduce the extension call on Windows under python.exe and pythonw.exe, using the reported traceback technique if needed. Done means the binding no longer crashes under pythonw.exe and the behavior is covered by a regression check.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
backend-api-design, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.