From 75c3b33550624fecb551b16f95ea65bf3323934f Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 25 Jan 2024 17:15:33 +0100 Subject: linuxnamespaces.run_in_fork: use os._exit instead of sys.exit When using sys.exit, we actually raise a SystemExit exception and as a consequence exit all context managers. If a particular context manager pertains only the process at hand, we don't really care, because our process is supposed to vanish. If a context manager changes external state such as tempfile.NamedTemporaryFile, this is very bad and unexpected. We need to ensure that such cleanup is not performed. This also simplifies the test suite that had to emulate this behaviour already as pytest uses a context manager. --- linuxnamespaces/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'linuxnamespaces/__init__.py') diff --git a/linuxnamespaces/__init__.py b/linuxnamespaces/__init__.py index f44220a..c060e01 100644 --- a/linuxnamespaces/__init__.py +++ b/linuxnamespaces/__init__.py @@ -210,7 +210,7 @@ class run_in_fork: self.efd.read() self.efd.close() function() - sys.exit(0) + os._exit(0) def start(self) -> None: """Start the decorated function. It can only be started once.""" -- cgit v1.2.3