pybind / pybind/pybind11

[QUESTION] How to execute on other thread and stop execution by user

Open
#2,677 5 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

Hi,

I made a simple sample that:

  1. Start a C++ thread
  2. Execute python code with pybind11 in the thread created
  3. Check if "stopped" variable is true and interrupt execution

Sample:
https://github.com/prsolucoes/pybind11-test/blob/master/src/cpp/main.cpp#L26-L35

The problem:
The line "py::exec(content);" block thread execution and i need that it stop run when "stopped" variable is "true".

Question:
How can i execute the python code and stop it while it is running correctly?

Thanks.

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 sample at src/cpp/main.cpp#L26-L35 and inspect how py::exec(content) runs in the created C++ thread. Research pybind11's execution and interruption behavior, including the stopped flag, then determine what a correct user-controlled stop would require.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.