简体   繁体   中英

How can I stop python script using putty on debian server

I run a python script:

python main.py

Ok, its running in infinite while loop. How can I stop in one (ACTUAL) session putty?

Ctrl + c not working.

Only close putty, open again and kill the process help me.

Thank you for your help.

Does your code use the signal module catching SIGINT? Or is it catched via KeyboardInterrupt somewhere in the code (hard to say without the code for me)?

One thing you could do is to start your process in a virtual terminal like screen - which you can quit via CTRL-A D and then kill the process outside.

Try Ctrl + z; bg and then kill.

yalca:~ farax$ python
Python 2.7.10 (default, Feb  7 2017, 00:08:15) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

ctrl + z

[1]+  Stopped                 python
yalca:~ farax$ bg
[1]+ python &

[1]+  Stopped                 python
yalca:~ farax$ jobs
[1]+  Stopped                 python
yalca:~ farax$ kill %1
[1]+  Terminated: 15          python
yalca:~ farax$ 
  1. Ctrl + z => stop foreground process
  2. bg => continue process in background
  3. kill %1 => kill background process nr 1 (shown by jobs command)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM