-1

i have a linux remote server when run a python script in a virtual enviroment. I start this script with

source ./venv/bin/activate
python3 ./main.py

and it works without problem. Now, how can I stop this script? At now, I have to reboot my remote server to stop it.

Any suggestions? Thank you!

franzi98
  • 33
  • 1
  • 7
  • 1
    You can stop it the same way you would stop any process. Activating the virtual environment only affects the shell. Running `python3` still just starts an ordinary process – Brian61354270 Mar 16 '23 at 14:01
  • 1
    https://stackoverflow.com/questions/19782075/how-to-stop-terminate-a-python-script-from-running – Jatin Morar Mar 16 '23 at 14:04
  • This could be an idea but I hope to find something better. I am looking for process name with ps -e and I have some instances of python3 and I have to be lucky to stop the right one. I have more than one script running in virtual enviroment and more than one process with same name. However thank you for your reply – franzi98 Mar 16 '23 at 14:16
  • @JatinMorar Found a solutition inside that question. With 'pkill -f scriptname' i can stop a script running inside a virtual enviroment. Thanks a lot! – franzi98 Mar 16 '23 at 14:34

1 Answers1

1

You can use kill command or Ctrl + C

kill PID

or you can as well use:

pkill -f main.py
Abdulmajeed
  • 1,502
  • 2
  • 10
  • 13
  • Hello Abdulmajeed, CTRL + C can't help me because my program doesn't run in intercative mode. Kill command is quite comfortless because I have to search PID with relative name and I have more than one script in different virtual enviroments and every process have the same name 'python3' Pkill -f main.py sava me. Thank you a lot! – franzi98 Mar 16 '23 at 14:45