[Python] Python process still running in OS (Ubuntu) after the program has finished

Discussão em 'Python' iniciado por Stack, Julho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I have a number of python 3.12 scripts running at various times. When I am developing in Pycharm (current version 2025.1.) the script usually does not finish, I have to click on the Stop button. The last line of my script executes though. Even adding a final exit(code=None) does not make any difference. The same when I run from a terminal, I have a number of python processes still running that I have to manually kill from the Ubuntu terminal.

    When I have to click on the Stop button in Pycharm to terminate the script I get the following:

    Exception ignored in: <module 'threading' from '/usr/lib/python3.12/threading.py'>
    Traceback (most recent call last):
    File "/usr/lib/python3.12/threading.py", line 1622, in _shutdown
    lock.acquire()
    KeyboardInterrupt:


    before getting Process finished with exit code 0.

    Annoyingly, sometimes the script will terminate correctly, but under what circumstances I don't know. As it is a fairly long program I can't include it here, nor am I able to reproduce the problem with something that I can post here. I am currently not using any subprocesses or threads, but I am accessing a MySQL database.

    Can anybody suggest something that I can try to prevent the problem, or maybe a simple/clean way of automatically killing a process from within python if it keeps running?

    Regards, StuartM

    Continue reading...

Compartilhe esta Página