-
Notifications
You must be signed in to change notification settings - Fork 468
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
python scripts is not reinitialized during SIGHUP #1370
Comments
Just a little summary on the progress on this topic: The documentation does not state that we should recompile user code during reload. This one is the closest one to it: As for the implementation: python does not support unimporting modules. At least there is no api call for it. One might think if we drop a reference count, that would trigger the garbage collector, but the thing is when you import a module, the reference counter of the returned module object will be 2 instead of 1. The reason is an additional reference is set, due to the module object is added to the An alternative could be is: we could stop the whole python machinery, and recreate it after reload. A downside of this that it would disable such techniques we use in syslog-ng core: like persist-config. Users might want to save data across reloads, which could not be achieved if the python machinery is stopped in the middle. The good news is: reimporting modules is supported by the c api PyObject* PyImport_ReloadModule(PyObject *m). I tried this, and it works as expected, the modified user code is activated after reload. We could store the module object in the PythonDestDriver class: create it with PyObject* PyImport_Import(PyObject *name), reload it with PyImport_ReloadModule. |
I was tinkering with this one a little bit more, and it seems my patch had an unwanted side effect, it broke the persistence: with the following config
the original code prints increasing values of Another topic: I found this exciting module: mem_top which can be installed from pip. This module can help to check if we leak python objects in our module. One can use to check leak problems with reloads. |
Reproduction:
print("test message")
print()
statement is not logged to consoleThe text was updated successfully, but these errors were encountered: