Python Forum
Stopped process is still running
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stopped process is still running
#1
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?
Reply
#2
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.
Reply
#3
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.
Reply
#4
Then you have no process that continues after the program exits (Ctrl+c kills everything).
Reply
#5
If Ctrl+c kills everything, why after new running script, it doesn't display menu, but it runs function1?
Reply
#6
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.
Reply
#7
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?
Reply
#8
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.
Reply
#9
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.
Reply
#10
I think it can be debugged only if you post the complete code, or a link to the code.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Spyder stopped working in Windows 10 gammaray 3 3,067 Apr-19-2021, 05:33 PM
Last Post: jefsummers
  Get stdout of a running process yok0 0 3,020 Aug-20-2020, 10:12 AM
Last Post: yok0
  How to sharing object between multiple process from main process using Pipe Subrata 1 3,661 Sep-03-2019, 09:49 PM
Last Post: woooee
  Multiprocessing Module Running An Infinite Child Process Even After Completion hsikora 0 3,879 Dec-19-2018, 08:01 AM
Last Post: hsikora
  python has stopped working sally 1 6,020 Nov-22-2018, 10:19 PM
Last Post: metulburr
  Pausing a running process? MuntyScruntfundle 2 7,243 Nov-14-2018, 05:14 PM
Last Post: woooee
  running just one process shared among uses Skaperen 3 2,986 Aug-07-2018, 12:12 AM
Last Post: Skaperen
  mkdtemp spontaneously stopped working reliably last night saporta98 1 2,818 Apr-16-2018, 05:12 PM
Last Post: nilamo
  urlparse to urllib.parse - the script stopped working apollo 5 6,662 Oct-26-2017, 06:57 AM
Last Post: apollo
  Logging module stopped working! llanitedave 1 7,971 Oct-18-2017, 06:45 AM
Last Post: llanitedave

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020