while result != 'it worked!!':
    q = Queue()
p = SafeProcess(q, target=unreliable_code)
p.start()
t = Timer(1, p.terminate)
t.start()
p.join()
t.cancel()
try:
    result = q.get_nowait()
except queues.Empty:
    print('Empty')
print(result)
How to safely run unreliable piece of code?