Hi,
I am writing a Python script that will start two threads: one thread shall start the client application and catch logs from it and the other thread shall catch logs from the server side.
So the first thread knows when it shall stop since it has a set of actions to be performed and when all it's tasks are done it simply terminates.
Now i would like the other thread to terminate itself as soon as the first thread is gone.
I have solved this problem with global event, so now it looks like this:
and here is a part of code from the server thread
At this moment it just prints the logs from the server to the screen.
So this is my temporary solution. I would like to do it in other way. When the client thread is about to terminate it could send signal like "I am done." so the server thread would know when it should terminate.
How can I do that?
Thanks in advance!
Best regards,
I am writing a Python script that will start two threads: one thread shall start the client application and catch logs from it and the other thread shall catch logs from the server side.
So the first thread knows when it shall stop since it has a set of actions to be performed and when all it's tasks are done it simply terminates.
Now i would like the other thread to terminate itself as soon as the first thread is gone.
I have solved this problem with global event, so now it looks like this:
Code:
if __name__ == '__main__':
stopEvent = Event()
client = Client()
client.start()
server = Server()
server.start()
Code:
while not stopEvent.isSet():
print self.connection.readOutput()
So this is my temporary solution. I would like to do it in other way. When the client thread is about to terminate it could send signal like "I am done." so the server thread would know when it should terminate.
How can I do that?
Thanks in advance!
Best regards,
Comment