-
Notifications
You must be signed in to change notification settings - Fork 203
WIP: atexit handling in Ansible modules #1388
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
base: master
Are you sure you want to change the base?
Conversation
|
I expect the test to fail, based on ➜ ansible git:(issue1360) ✗ ANSIBLE_STRATEGY=linear ansible localhost -m atexit_cleanup
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
localhost | CHANGED =>
changed: true
➜ ansible git:(issue1360) ✗ ls -l /tmp/mitogen_test*
zsh: no matches found: /tmp/mitogen_test*➜ ansible git:(issue1360) ✗ ANSIBLE_STRATEGY=mitogen_linear ansible localhost -m atexit_cleanup
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
localhost | CHANGED =>
changed: true
➜ ansible git:(issue1360) ✗ ls -l /tmp/mitogen_test*
-rw-r--r--@ 1 alex wheel 0 Dec 4 09:42 /tmp/mitogen_test_atexit_cleanup_canary.txt |
|
In old CPython (probably 2.x) atexit was a pure Python module. The list of registered callbacks was stored in In current CPython (since python/cpython@670e692) atexit is a builtin module and the list of handlers is stored internally. I don't see a way to introspect it. The number of handlers can be introspected, and maybe > 0 depending how CPython was started |
|
From
|
|
Two third party packages worth perusing
The limitation is that third-party packages (e.g. kubernetes client) are already using these, so they may not be applicable as is. |
|
Reproduced with just Mitogen import atexit
import sys
import os
import mitogen.master
def cleanup(file):
try:
os.unlink(file)
except FileNotFoundError:
pass
def foo(file):
atexit.register(cleanup, file)
with open(file, 'wb') as f:
f.truncate()
return 42
if __name__ == '__main__':
broker = mitogen.master.Broker()
router = mitogen.master.Router(broker)
context = router.local(python_path=sys.executable)
canary = '/tmp/issue1360_canary.txt'
cleanup(canary)
result = context.call(foo, canary)
print(result)➜ mitogen git:(issue1360) ✗ python3 issue1360.py
42
➜ mitogen git:(issue1360) ✗ ls /tmp/issue1360_canary.txt
/tmp/issue1360_canary.txt |
Pin down if (and when) callbacks added by
atexit.register()are executed. Fix or document shortcomings.refs #1360