So I have two python programs:
main.py sub.py Main contains import sub.py, and sub.py contains os._exit(0). Problem is that I don't want to close both programs, only sub.py. Is this possible?
You don't have "two python programs", you have two python modules, one of them used as the "main" script (the one your actually execute) and importing the other. At runtime you only have one process, and os._exit() kills this process, period.
The fix is very obviously to not use os._exit() at all.
main.pybefore launchingsub.pypython main.pyand if you importsub.pyit becomes part of that process. It is not a program on its own.