title: How do I 'sleep' python without pausing entire script
body: <p>I'm fairly new to python and am trying to make a basic stopwatch script. I want to be able to pause the stopwatch, but the <code>time.sleep(1)</code> code which waits for the next number to be shown interferes with the keyboard event. BTW I'm using the python package 'keyboard' to get the event. I have tried threading but I can't pause the other thread as far as I know.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>import time, keyboard, sys
  
  print('Stopwatch \n')
  input('Press enter to start:')
  
  def counter():
      stopwatch = 0
      while True:
          time.sleep(1)
          stopwatch += 1
          print(stopwatch)
          question()
  
  def question():
      while True:
          if keyboard.is_pressed('p'):
              print('\nPaused')
              input('Press enter to resume:')
          if keyboard.is_pressed('s'):
              print('\nStopped')
              sys.exit()
  
  counter()
  </code></pre>
  
  <p>I don't necessarily need the <code>question</code> function, but was experimenting to see if I could get it to work. I could combine the two functions.</p>