0

What should be written in kill_input() instead of pass to stop input() and terminate the program?

#!/usr/bin/env python3

import threading, time

running = True

def kill_input():
  pass

def input_reader():
  while running:
    print(input())

t = threading.Thread(target = input_reader)
t.start()

time.sleep(2)
kill_input()
print('bye')
vpas
  • 371
  • 1
  • 3
  • 16
  • If you want an input prompt with a timeout you may want to check https://stackoverflow.com/a/15533404/3488231 – user12205 Aug 10 '18 at 07:36

1 Answers1

0

Solved with setting the thread to daemon. t.daemon = True t.start()

If there are no hanging non-daemon threads it will terminate automatically.

vpas
  • 371
  • 1
  • 3
  • 16