Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working with Python Django in Windows Vista Powershell. After I run python runserver , it asks me to CTRL-BREAK to stop the process. But after I typed that, Powershell stops the process and closes. Is there a way to stop the process and keep the Powershell open?

share|improve this question
This django-windows default is terrible for lots of reasons (like the fact that many laptops and even the built-in virtual keyboard don't have a break key). I wish I could find a work-around. – Mortoc Aug 30 '13 at 18:22
Python often lies about what to do to exit/stop a process. But you can try other CTRL-<options>. For example: CTRL-C/Z/D – user1147688 Feb 26 '14 at 22:12
@user1147688 ctrl+break instantly kills the python interpreter on windows while ctrl+c can be catched or ignored. – Smit Johnth May 3 '15 at 18:10
up vote 3 down vote accepted

Unfortunately the PowerShell console host uses Ctrl+C to terminate an ongoing operation and Ctrl+Break terminates the operation AND closes the host session. It's a most unfortunate choice IMHO but it's there and we get to live with it.

I find the easiest thing to do when I run into situations like this is from the PowerShell session simply execute cmd from the PowerShell prompt. Now I'm actually bypassing PowerShell temporarily and I'm easily back to my PowerShell session when done.

The other thing you should probably consider is using cmd.exe rather than PowerShell unless there is some feature of PowerShell you're trying to leverage.

share|improve this answer

You may try it in this way:

  1. Your powershell launches your python program in a job

  2. Trap Ctrl-C by the powershell main process

  3. When Ctrl-C is trapped, stop the job launched in step 1

Then, you can keep your powershell script continuing

  1. To launch a background job, use start-job

    $killMe = start-job -scriptblock {&python}

  2. To trap Ctrl-C, tell your console to treat Ctrl-C as an input, check this from MSTN.

    [console]::TreatControlCAsInput = $true

Then run an UI loop for checking keys input:

while ($true) {

  write-host "Processing..."
  if ([console]::KeyAvailable) {

    $key = [system.console]::readkey($true)
    if (($key.modifiers -band [consolemodifiers]"control") -and
      ($key.key -eq "C")) {

  1. To stop the job when the "Ctrl-C" is hit,

    stop-job -job $killMe

However, life will not be easy if you need to interact with your python server, which is running at the background. And you would probably like to display your server's output constantly.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .