How to get Python garbage collection to run a script

To investigate some issues with unreleased system resources, I would like to force the garbage collection to be displayed on the already running python script.

Is this possible, for example. by sending some kind of signal that Python will understand as an order to run gc; or any other similar way? Thanks.

I am running Python 2.7 on a Linux server.

+5
source share
2 answers

Install a signal handler using the built-in signal module, then call gc.collect () from your custom handler.

If you do not have control over the application, you will need to use something like pyringe , which will allow you to embed arbitrary python.

+2
source

You can connect to the running python script using the debugger and issue any command inside it, for example inside the interactive console. I used the PyCharm debugger, but there are many.

0
source

Source: https://habr.com/ru/post/1243951/


All Articles