Sublime Forum

How to avoid zombie subprocess?


I made a plugin that spawns a long-running subprocess on start and then it uses TCP socket to communicate with the child process:

The problem stumped me is if I close sublime text, the child process is still running in the background. Although I didn’t put any daemon options on subprocess/thread.

Now my workaround is if the address is in use (got EADDRINUSE error message), then I just send an exit command to this zombie process 🤷.

I don’t really understand how python’s subprocess/thread works. From my experience on ruby/js the child process should be terminated automatically when the parent one exits.

I want to know if someone has similar approach to plugins (i.e. has something running in the background) and how to fix this problem.



There is on_exit event listener. You may kill processes there.



Thank you, it works!