Skip to content

Process _bootstrap calls _exit_function #114220

Open
@albertz

Description

@albertz

Specifically, in this line:

util._exit_function()

Why is _exit_function called here in _bootstrap? The function _exit_function is also registered via atexit, so would run later otherwise.

This can be problematic. This means that the order of how the atexit handlers are normally called (in reverse order) is violated for the _exit_function function.

E.g. if some user code also calls atexit.register, that would usually be after the _exit_function has already been registered in atexit. So, at exit, the user atexit handlers would run first. There can be situations where the users code depends on this order of atexit handler calls.

E.g. the user creates some new (non-daemonic) sub proc, and then in some atexit handler, there is some proper cleanup, which would also lead to a termination of the sub proc. Then later, when _exit_function is called, the sub proc is terminated, so it is either already cleaned up, or otherwise it will join here at clean it up.

Now, if _exit_function is executed before the user atexit handler, it means it will try to join, and just hang there. (And this is exactly the problem we had here: rwth-i6/returnn#1497)

So, my suggestion is to remove the exit_function in _bootstrap, and rely on the atexit logic, which should then execute in the right order.

But maybe there was some reason to call exit_function here in _bootstrap which I don't know?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions