Ctrl C Doesn T Work

Try different key combo such as: Ctrl key on the left side along with the Shift key on right side with the C key all together. This should work in both Sims 3 and 4. This is not really a bug, but a issue that players run into. In the post linked below, you can find some tips on how to fix the problem. Ctrl-C and Ctrl-V stopped working after a Windows update on my Toshiba Satellite laptop. External keyboard works but kind of m. If this doesn't work, you may wish to try connecting an external keyboard and see if it works fine. You may also want to try updating the Synaptics Driver if the above doesn't help. Ciprianagapi Prominent.

  1. Ctrl C Does Not Work Windows 10
  2. Ctrl C Doesn't Work Ubuntu

I have a python script that uses threads and makes lots of HTTP requests. I think what's happening is that while a HTTP request (using urllib2) is reading, it's blocking and not responding to CtrlC to stop the program. Is there any way around this?

udondan
36.5k10 gold badges132 silver badges139 bronze badges

Ctrl C Does Not Work Windows 10

jonatronjonatron
7662 gold badges5 silver badges10 bronze badges

11 Answers

On Windows, the only sure way is to use CtrlBreak. Stops every python script instantly!

(Note that on some keyboards, 'Break' is labeled as 'Pause'.)

Chris Stratton
36.1k5 gold badges65 silver badges106 bronze badges
Denis MasyukovDenis Masyukov
2,0223 gold badges19 silver badges18 bronze badges

Pressing Ctrl + c while a python program is running will cause python to raise a KeyboardInterrupt exception. It's likely that a program that makes lots of HTTP requests will have lots of exception handling code. If the except part of the try-except block doesn't specify which exceptions it should catch, it will catch all exceptions including the KeyboardInterrupt that you just caused. A properly coded python program will make use of the python exception hierarchy and only catch exceptions that are derived from Exception.

If you can't change the code (or need to kill the program so that your changes will take effect) then you can try pressing Ctrl + c rapidly. The first of the KeyboardInterrupt exceptions will knock your program out of the try block and hopefully one of the later KeyboardInterrupt exceptions will be raised when the program is outside of a try block.

Toby Speight
18k13 gold badges48 silver badges69 bronze badges
David LockeDavid Locke
9,8348 gold badges28 silver badges50 bronze badges

If it is running in the Python shell use Ctrl + Z, otherwise locate the python process and kill it.

Andrew HareAndrew Hare
286k55 gold badges592 silver badges608 bronze badges

The interrupt process is hardware and OS dependent. So you will have very different behavior depending on where you run your python script. For example, on Windows machines we have Ctrl+C (SIGINT) and Ctrl+Break (SIGBREAK).

So while SIGINT is present on all systems and can be handled and caught, the SIGBREAK signal is Windows specific (and can be disabled in CONFIG.SYS) and is really handled by the BIOS as an interrupt vector INT 1Bh, which is why this key is much more powerful than any other. So if you're using some *nix flavored OS, you will get different results depending on the implementation, since that signal is not present there, but others are. In Linux you can check what signals are available to you by:

So if you want to catch the CTRL+BREAKsignal on a linux system you'll have to check to what POSIX signal they have mapped that key. Popular mappings are:

In fact, many more functions are available under Linux, where the SysRq (System Request) key can take on a life of its own..

wallyk
49.4k10 gold badges68 silver badges125 bronze badges
not2qubitnot2qubit
4,8752 gold badges42 silver badges69 bronze badges

This post is old but I recently ran into the same problem of CTRL+C not terminating python scripts on my Linux. I used the CTRL + (SIGQUIT).

Junius L.Ctrl c doesnJunius L.

Ctrl C Doesn't Work Ubuntu

8,8052 gold badges18 silver badges42 bronze badges

Ctrl+C Difference for Windows and Linux

It turns out that as of Python 3.6, the interpreter handles SIGINT generated by Ctrl+C differently for Linux and Windows. For Linux, ctrl+c would work mostly as expected however on Windows ctrl+c mostly doesn't work if call is blocking such as thread.join or waiting on web response (it does work for time.sleep, however). Here's the nice explanation of what is going on in Python interpreter.

Solution 1: Use Ctrl+Break or Equivalent

Use below keyboard shortcuts in terminal/console window which will generate SIGBREAK at lower level in OS and terminate the Python interpreter.

Mac OS and Linux

Ctrl + Shift + orCtrl +

Windows:

  • General: Ctrl+Break
  • Dell: Ctrl+Fn+F6 or Ctrl+Fn+S
  • Lenovo: Ctrl+Fn+F11 or Ctrl+Fn+B
  • HP: Ctrl+Fn+Shift
  • Samsung: Fn+Esc

Solution 2: Use Windows API

Below are handy functions which will detect Windows and install custom handler for Ctrl+C in console:

You can use above like this:

Solution 3: Polling method

I don't prefer or recommend this method because it unnecessarily consumes processor and power negatively impacting the performance.

import threadingimport time

Shital ShahShital Shah
28.2k6 gold badges119 silver badges103 bronze badges

On Mac press:

'control' + ' '

to quit a python process attached to a terminal.

KrunalKrunal
4,2181 gold badge12 silver badges16 bronze badges

On a mac / in Terminal:

  1. Show Inspector (right click within the terminal window or Shell >Show Inspector)
  2. click the Settings icon above 'running processes'
  3. choose from the list of options under 'Signal Process Group' (Kill, terminate, interrupt, etc).
davejal
4,4599 gold badges26 silver badges59 bronze badges
AG452AG452
  • Forcing the program to close using Alt+F4 (shuts down current program)
  • Spamming the X button on CMD for e.x.
  • Taskmanager (first Windows+R and then 'taskmgr') and then end the task.

Those may help.

The dark side of GamingThe dark side of Gaming

For the record, what killed the process on my Raspberry 3B+ (running raspbian) was:

On my French AZERTY keyboard, the touch ' is also number 4.

BertinchampsBertinchamps

You can open your task manager (ctrl + alt + delete, then go to task manager) and look through it for python and the server is called (for the example) _go_app (naming convention is: _language_app).

If I end the _go_app task it'll end the server, so going there in the browser will say it 'unexpectedly ended', I also use git bash, and when I start a server, I cannot break out of the server in bash's shell with ctrl + c or ctrl + pause, but once you end the python task (the one using 63.7 mb) it'll break out of the server script in bash, and allow me to use the git bash shell.

JORDANOJORDANO

Not the answer you're looking for? Browse other questions tagged python or ask your own question.

Ctrl + C doesn't always work to kill the current process (for instance, if that process is busy in certain network operations). In that case, you just see '^C' by your cursor and can't do much else.

What's the easiest way to force that process to die now without losing my terminal?

Summary of the answers:Usually, you can Ctrl + Z to put the process to sleep, and then do kill -9 _process-pid_, where you find the process's pid with ps and other tools. On Bash (and possibly other shells), you can do kill -9 %1 (or '%N' in general) which is easier. If Ctrl + Z doesn't work, you'll have to open another terminal and kill from there.

Peter Mortensen
8,46616 gold badges61 silver badges85 bronze badges
Dustin BoswellDustin Boswell
9514 gold badges11 silver badges11 bronze badges

9 Answers

To understand the problem of why Ctrl + C does not work, it is very helpful to understand what happens when you press it:

Work

Most shells bind Ctrl + C to 'send a SIGINT signal to the program that currently runs in the foreground'. You can read about the different signals via man signal:

Programs can ignore that signal, as they can ignore SIGTSTP as well:

(Which is what most shells do when you press Ctrl + Z, which is why it is not guaranteed to work.)

There are some signals which can not be ignored by the process: SIGKILL, SIGSTOP and some others. You can send these signals via the kill command. So, to kill your hanging / zombieying process, just find the process ID (PID). For example, use pgrep or ps and then kill it:

Peter Mortensen
8,46616 gold badges61 silver badges85 bronze badges
akiraakira
50.5k15 gold badges115 silver badges153 bronze badges

If Ctrl+C (SIGINT) doesn't work, try Ctrl+ (SIGQUIT). Then try Ctrl+Z (SIGTSTP). If that returns you to a shell prompt, do kill on the process ID. (This defaults to the SIGTERM signal, which you can specify with kill -TERM. In some shells, you may be able to use %1 to refer to the PID.) If that doesn't work, go to another terminal or SSH session and do kill or kill -TERM on the process ID. Only as a last resort should you do kill -KILL, a.k.a. kill -9, as it doesn't give the process any chance to abort cleanly, sync its open files, remove its temporary files, close network connections, etc.

G-Man
6,24011 gold badges25 silver badges63 bronze badges
TeddyTeddy
5,1843 gold badges14 silver badges15 bronze badges

Press Ctrl-Z to suspend the program and put it in the background:

(Restore to foreground again using fg)

Then, you can kill or kill -9 it, given its process ID (you get that from ps a).

akira
50.5k15 gold badges115 silver badges153 bronze badges
Daniel BeckDaniel Beck
94.6k12 gold badges240 silver badges290 bronze badges

See this link as well.

Ctrl+Z: pause a process.

Ctrl+C: politely ask the process to shut down now.

Ctrl+: mercilessly kill the process that is currently in the foreground

Community
RoboAlexRoboAlex

Usually, you can still stop the process (Ctrl + Z) and then use kill -9. For kill -9, you need the process PID first. For background jobs, kill -9 %1 is easiest way to do it - if you are unsure what is the number of background job you want to kill, run jobs.

Alternatively, you can find process ID with

Then you can run

OlliOlli
6,3163 gold badges28 silver badges46 bronze badges

1) If you are on the console and in multi-user mode, you could press CTRL-ALT-Fn and login on another screen, use ps -ef grep <myprocessname> or pidof <myprocessname> and then kill -9 the process by ID number.

2) If you are connected remotely, do the same via another terminal session.

You could also make life a little easier by installing htop, which is a more versatile version of top that allows you to selectively kill running processes. Most distros have htop in a repo.

3) if you are just stuck in a hung ssh session (to another system, for example), try pressing tilde (~), which is the escape key, and then press CTRL-Z to drop back to the host session, then you can kill the stuck ssh process or wait for it to timeout, which most sill do after a period of inactivity.

Linker3000Linker3000
25k3 gold badges43 silver badges65 bronze badges

A simpler solution for Bash (and other shells?) is to do:

where '%1' refers to the job number being killed. It might be '%2' (or something else) if you already have other jobs sleeping. You can see which job number it is when you hit Ctrl-z:

Note that 'kill' is the shell's version of kill, not /bin/kill.


If you are using tmux or screen, and none of the above works, you could still kill the pane by <prefix> x, then the process is also killed.

STAR WARS MOVIE HEROES GALACTIC BATTLE GAME SERIES R2-D2 FIGURE HASBRO 2012. Guaranteed by Tue, Jun. Buy It Now +$5.66 shipping. 13 new & refurbished from $11.99. Tiger Star Wars Electronic Galactic Battle Battleship 1997 Extra Imperial Ships. Welcome to Galactic Battle, the strategic space combat game of the Star Wars galaxy. As commander of either the Rebel Alliance or the Empire, an entire fleet of starships awaits your command. The fate of the galaxy is in your hands! Star wars galactic battle game. Vintage Star Wars Electronic Galactic Battle Game Tiger Electronics Inc. 5.0 out of 5 stars. 4 product ratings - Star Wars Galactic Battle Space Combat Electronic Game Battleship 1997.WORKS. $24.99. Or Best Offer +$11.99 shipping. 1 new & refurbished from $75.00. Star Wars Galactic Heroes Mini Action Figure - Luke Skywalker with Green Lightsaber and Gamorrean Guard with Battle Axe. This game is a pack in with every Hasbro 3.75 inch Star Wars action figure. Each figure comes with a stat card with bonus powers, a base to hold the figure and the card and a die. The die is custom and has 6 Star Wars symbols on it. Make up your army of figures from as few or as many as you want. Pick an opponents figure to battle and roll the dice.

ospiderospider

There maybe a trap set with SIGINT(2) in your /etc/profile. If so, remove it. Logout and log back in and you should be good.

TechNo_phileTechNo_phile

Not the answer you're looking for? Browse other questions tagged linuxbashshell or ask your own question.

Comments are closed.