Open tstrutz opened 5 months ago
I may have figured out what was causing this. It looks like Panel is holding onto Panel resources even after the Python interpreter exits. Maybe a leak of some kind?
Anyways, I found that running pn.state.kill_all_servers()
as the last line in main.py eliminates all of the problems here. I also moved all of the variables to a def main
function so that there are zero global variables other than the app object. The weird thing with this is I am stopping the server. It shouldn't be running, unless the state is still left behind?
Why doesn't panel automatically do this clean up operation when Python exits? It's probably a good idea.
def main(app):
# Pybinding object.
launcher = AppLauncher(app)
launcher.run()
if __name__ == "__main__":
print("Creating C++ application")
app = cpp_app_test.Application()
print("C++ application created.")
main(app)
print("Exiting interpreter. Destructors should be called after this point!")
pn.state.kill_all_servers()
produces the output:
Creating C++ application
Constructed application.
C++ application created.
Launching server at http://0.0.0.0:5000
^CCaught signal 2, shutting down...
Delete main page
Exiting interpreter. Destructors should be called after this point!
Delete home page
Destroyed application
I've noticed that the full application which contains a Sidebar and a Controller still doesn't work though. I may just reduce the number of references to self_app
to fix this.
I am experiencing an issue with a hybrid C++ and Python integrated app using Panel. More information below.
ALL software version info
VCPKG GCC 11.4.0 (C++ 17 Requirement) Ninja CMake 3.22.1 Python 3.10 Numpy 1.24.4 Panel 1.4.2 Bokeh 3.4.1 Param 2.1.0 Pybind11 C++ (Latest) WSL Ubuntu 22.04
Please also set VCPKG_ROOT to the location of your installed VCPKG to test this. We use that in a CMakePresets file.
Description of expected behavior and the observed behavior
Application works as expected, but cleanup DOES not. I create a C++ object in C++ using python bindings generated using pybind11. This object is passed to the my Panel Dashboard, and it's state is used to populate several features of the dashboard. This dashboard is a real-time visualization tool for an algorithm written in C++.
Further testing has indicated that destructors on several of my Panel objects are not getting called. My Dashboard view contains a tab that the destructor never gets called on. The full version contains several tabs, plots, a controller, and a data model populated by the C++ object. All of this is stripped out for simplicity.
There is some cleanup such as closing output files that often occurs when the destructors get called in the full application, but this is not happening due to this bug.
Complete, minimal, self-contained example code that reproduces the issue
Basic Dashboard and C++ Application Launcher
main.py
Stack traceback and/or browser JavaScript console output
C++ Code app.hpp
app.cpp
Python binding code app_pybind.cpp
Build Stuff
CMakePresets.json
vcpkg.json
CMakeLists.txt
How to build the minimum viable code
Create and place all files within the same folder. I can upload a zip if that makes it easier.
To run
Run the following in the same folder the files are in.
Notice, how python exits and the application does NOT call the C++ destructor.
Screenshots or screencasts of the bug in action