-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Child Class Method Not Being Called as Expected, Base Class Method Called Instead #1552
Comments
I'll pay actual money for a solution to my problem!! https://www.upwork.com/job/Fix-bug-Simple-Python-PyBind11-Module_~01155fc34bd0078416/ |
Opened up a stackoverflow question as well: |
Uploaded project sources and CMakeList file. Also included a version written in pure python to show how it should work. |
After I've seen your job proposition was closed, I've decided to at least create an issue based on my experience with this problem, which led me to this page. I am fairly certain it's a pybind11 bug, but its nature is a mystery. At first I thought it would be similiar to #1389, but SomeClient object is alive for the entire duration of a program. It seems that the problem is caused by the following sequence: |
In
(both sides of this are |
Possibly relates:
@bgoodman44 Even though it's 2 years late, do you still have stake in this issue? If so, can you see #2092 might fix your issue? |
FYI Rather than #2092, you can try the later PR, #2772 EDIT: Or rather, can you try latest master? @YannickJadoul's PR, #2564? |
Trying out repro - can reproduce your issue on latest master: |
I think it was because you relied on an odd recursive dispatch between I simplified your example, and could make it work: 597752a $ cd pybind11
$ mkdir build && cd build && cmake .. && env PYTEST_ADDOPTS="-s -x" make pytest
../../tests/test_issue1552.py In Dispatcher::Dispatcher
...
In SomeClient::__init__
In Client::Client
Dispatcher::Dispatch called by 0x1491850
Python ProcessEvent For more details on how to configure the tests, please see: Closing for now. |
Hello,
I have a simple test case for polymorphism that isn't working quite right.. I have two C++ classes, Client and Dispatcher. Dispatcher has a method called "Dispatch" that takes a Client* as an input, and calls the the clients virtual ProcessEvent() method. I've made both of these classes available to python using the code below. I've derived from the Client class as the python class SomeClient, and overridden its ProcessEvent function. When I call "Dispatch" from anywhere EXCEPT inside the SomeClient::ProcessEvent method, everything works as expected, i get a report from the child class. But when I call Dispatch from within SomeClient::ProcessEvent, the base classes ProcessEvent is called. Any ideas what could be going wrong here? I expect to get an infinite recursion that results in SomeClient::ProcessEvent being called forever.
C++:
Python Test:
TERMINAL OUTPUT:
The text was updated successfully, but these errors were encountered: