atexit

Freeing in an atexit()

ぐ巨炮叔叔 提交于 2019-11-28 02:56:21
问题 Is there any point to freeing memory in an atexit() function? I have a global variable that gets malloc'ed after startup. I could write an atexit() function to free it, but isn't the system going to reclaim all that memory when the program exits anyway? Is there any benefit to being tidy and actively cleaning it up myself? 回答1: Not in C - it's like rearranging the deck chairs while the ship sinks around you. In C++ the answer is different, because objects can delete temporary files and so

How to find exit code or reason when atexit callback is called in Python?

天涯浪子 提交于 2019-11-27 21:19:14
I want to know if a Python script is terminating correctly or not. For this I am using atexit but the problem is that I do not know how to differentiate if atexit was called with sys.exit(0) or non zero or an exception. Reasoning: if program ends properly, it will do nothing but if the program ends by an exception or returning an error code (exit status) different than zero I want to trigger some action. In case you will wonder why I'm not using try/finally is because I want to add the same behaviour for a dozen of scripts that are importing a common module. Instead of modifying all of them, I

How to find exit code or reason when atexit callback is called in Python?

时间秒杀一切 提交于 2019-11-27 04:30:35
问题 I want to know if a Python script is terminating correctly or not. For this I am using atexit but the problem is that I do not know how to differentiate if atexit was called with sys.exit(0) or non zero or an exception. Reasoning: if program ends properly, it will do nothing but if the program ends by an exception or returning an error code (exit status) different than zero I want to trigger some action. In case you will wonder why I'm not using try/finally is because I want to add the same