pybind / pybind/pybind11

Strange deadlock with pybind11 + Flask w/ app debug mode

Open
#1,308 1 comment 1 reaction 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

Issue description

The exact setup for this to happen seems really bizarre to me, but here it goes: I get a deadlock when using Flask with its default debug app reloader with my pybind11 module. I've reduced the example down to the smallest thing I can think of that still replicates.

The ingredients:

  1. #include <pybind11/functional.h>
  2. A pybind11-bound function that takes a std::function
  3. A class defined in the module
  4. A Flask app running with app.run(debug=True)
  5. A route in that Flask app that calls the function from 2.

What really confuses me is that if I remove the class in step 3, the deadlock goes away. Similarly, if the function in step 2 doesn't take something complicated (like just an int), the deadlock goes away. If the call to run the app is instead just app.run(), the deadlock goes away (similarly if use_reloader=False is passed). Something in the combination of all three of these things causes the deadlock when the passed-in function is invoked. Using a default std::function parameter doesn't seem to change anything.

Versions:

$ python --version
Python 3.6.4

$ gcc --version
gcc (GCC) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

pybind11 stable branch (see submodule in reproduction repo)

Reproducible example code

https://github.com/skystrife/pybind11-bug

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 linked skystrife/pybind11-bug reproducible example and run the reported setup using the stated Python 3.6.4, GCC 7.3.0, Flask debug reloader, and pybind11 stable branch. Compare the cases with and without the class, std::function argument, and app.run(debug=True); done means the deadlock is understood and the reported route no longer hangs under the triggering combination.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
backend-api-design
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.