Q:

How to do computing until s is pressed? 

How can I do a computing program in Python 3 such that it does computing while program is running, shows the computing status when one presses s and quits the program when one presses ctrl+c?  I know I can use try-catch but how can I read when user presses s?  I know input but it stops the computing when waits the key press.  I'm using Ubuntu 17.04 on bash command line. 
I tried
n = 0
try:
    while True:
        n += 1
except KeyboardInterrupt:
    print("Stopping")

A:

Since you are on Linux you can use the curses module to do that. 
The way curses works is simple.  We set curses to "monitor" the compute() function (the keypress variable works as an event handler and you can call it as you wish - I chose to call it keypress).  
As you can also read in the documentation here, the most common way to get input to a window is to use its getch() method, but getch() pauses and waits for the user to hit a key.  To change this behavior we use the method nodelay(1).  By using nodelay(1), getch() for the window becomes non-blocking and returns curses. ERR (a value of -1) when no input is ready. 
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import curses

def compute(keypress):
    keypress.nodelay(1)
    n = 0
    try:
        while True:
            n += 1
            key = keypress.getch()
            if key ! = -1 and key==115: # ord('s')=115
                keypress.addstr(str(n) +'\n')
    except KeyboardInterrupt:
        sys.exit(0)

if __name__ == '__main__':
    curses.wrapper(compute)

