After looking at the KeyboardInterrupt to exit out of a multithreaded script I was wondering if it's possible to use the up and down keys on a keyboard to increase/decrease the number of threads being used? This would hopefully happen the same manner as KeyboardInterrupt so that it could happen at anytime. Is something like this possible or is there another method that would be better suited for this?
def do_something(input_file, threads):
concurrent = threads
l = read_csv(input_file)
for i in range(concurrent):
t = Thread(target=create_accounts)
t.daemon = True
t.start()
try:
for account in l:
q.put(account)
q.join()
except KeyboardInterrupt:
sys.exit(1)
if __name__ == '__main__':
threads = 1
q = Queue(threads * 2)
do_something('test.csv', threads)