Python Forum
Stopped process is still running - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Stopped process is still running (/thread-9412.html)



Stopped process is still running - pawlaczkaj - Apr-06-2018

I have got a menu written in Python:

if __name__ == '__main__':
    print_menu()    # display the menu
    choice = input("Type number")

    if choice == 1:
        function1()    # function, which calls the other functions
    if choice == 2:
        function2()
I had run function1 and before it reached the end I had stopped the script in terminal with Ctrl+C (I use Ubuntu 16.04). After it I want to check function2, but when I am running the script with menu, the menu is not displayed and it goes immediately to function1. It looks like the function1 is running whole the time, but when I check processes with ps ax there is not my script.

How can I terminate running function1?


RE: Stopped process is still running - woooee - Apr-06-2018

It depends on what is in function1. Are you using subprocess or multiprocessing to start a separate process? If you are using Python3.x, neither option will be run.


RE: Stopped process is still running - pawlaczkaj - Apr-07-2018

Function1 and function2 are collision avoidance algorithms which are sending to the simulator. They control the robot's moving as long as it reachs the goal.
I use only functions with loops. I am new in Python, so I don't know subprocess and multiprocessing.
I have the same problem when I use Python2.x and Python3.x too.


RE: Stopped process is still running - woooee - Apr-07-2018

Then you have no process that continues after the program exits (Ctrl+c kills everything).


RE: Stopped process is still running - pawlaczkaj - Apr-07-2018

If Ctrl+c kills everything, why after new running script, it doesn't display menu, but it runs function1?


RE: Stopped process is still running - Gribouillis - Apr-07-2018

After Ctrl-C, the program should print an exception traceback
Output:
Traceback (most recent call last): File XXX, line XXX, in <module> XXX KeyboardInterrupt
If it doesn't do that, there is another error somewhere.


RE: Stopped process is still running - pawlaczkaj - Apr-07-2018

But I have got this output. I think there is another problem.
Ctrl+c should "reset" the whole program and come back to start. Right?
When I run the same scripts, which are called in the menu, without the menu's script and I use ctrl+c everything is ok. I mean programm stop and when I run it again, it starts from the beginning. So in that case should I use subprocess or multiprocessing?


RE: Stopped process is still running - Gribouillis - Apr-08-2018

If you have this output, it means that the program exited. If the program does not start other processes or threads, there is nothing left of this program's execution. I don't understand your description with the menu: which menu are you talking about? Are you running the script from an IDE or from a terminal? Try to run the program from an ordinary terminal.


RE: Stopped process is still running - pawlaczkaj - Apr-08-2018

I have got menu.py with code from my first post. Also I have got algorithms' scripts: algorithm1.py and algorithm2.py. They are called in menu.py in function1 and function2.
At the beginning of my coding I wrote algorithms' scripts and I checked them. Everything worked as it should - after ctrl+c script ends and when I run it again, it starts from the script's first line. But when I test menu.py, I have a problem mentioned in posts - after ctrl+c script ends and when I run it again, it starts from the script's middle (it goes to the algorithm that was interrupted).
I run my scripts from terminal.


RE: Stopped process is still running - Gribouillis - Apr-08-2018

I think it can be debugged only if you post the complete code, or a link to the code.