I have a server running in the main thread, and a background process to impair network conditions in another thread. The server can only run in the main thread.
if __name__ == "__main__":
args = parse_args()
net_thread = Thread(target=run_net, args=(args,))
net_thread.start()
run_server(args.host, args.port, args.play_from, args.verbose, args.cert_file)
I want to rethrow any exceptions the background thread throws immediately. I found this answer, but the issue is that run_server
is blocking, so I can't join the net_thread after running the server.
I've thought about using an async coroutine to join the thread, but run_server
already has an async loop so I've run into problems there.
How can I immediately raise an exception in the main thread as soon as the worker thread runs into one?