I wish this helpful for you From a quick search of the error, I found this Github issue that seems to show your problem and its solution. It looks like you need to use asyncio and, at the beginning of each running thread, call asyncio.set_event_loop(asyncio.new_event_loop()).
from Queue import Empty, Queue
from threading import Thread
for key in iter(msvcrt.getch, 'q'): # until `q`
queue.put(None) # signal the end
q = Queue()
t = Thread(target=read_keys, args=[q])
t.daemon = True # die if the program exits
key = q.get_nowait() # doesn't block
key = Empty
if key is None: # end
# do stuff
This might help you Ok, lets break down your problem. First of all your main() method processes all the inputs and outputs to a file. When you use main with 2 threads same work is done by both the threads. You need a method that processes only one input and returns output for that input.