I have a small server-client setup to run some tools and gather some data. The idea is that the server will spin up multiple versions of clients one after the other and collect data via websocket. The server starts up like:
async def hello(websocket, path):
name = await websocket.recv()
[data collection and output happens here]
websocket.keep_running = False
asyncio.get_event_loop().stop()
subprocess.Popen(['C:\\Program Files\\APP\APP.exe', 'd:\\data\\app_input.txt'])
start_server = websockets.serve(hello, 'localhost', 8765)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
The problem is that I need to loop this such that I get data from multiple apps and they will all need to communicate via the socket. Once the server starts, I can terminate it, but I'd like it to keep running until all the tests are done. I was thinking something like:
for each app version:
[Get app parameters]
[Launch app, which will do the tests]
[Launch the server and collect the data being sent]
[Server terminates once signal from client is received]
But obviously this means the server starts and stops a fair amount. Is there a way to keep the server running in the background and then just terminate it once I'm done with everything?