0

Here I am creating 3 threads for one server and 2 clients. I wanted to stop the thread and make the port numbers reusable after one execution. My code is

t1=threading.Thread(target=serv)
t2=threading.Thread(target=cli1)
t3=threading.Thread(target=cli2)

t1.start()
time.sleep(2)
t2.start()
time.sleep(2)
t1.start()
time.sleep(2)

Here serv, cli1 and cli2 are the functions that contains client server programs.

How do I terminate these threads ?

Aditya Vikas Devarapalli
  • 3,186
  • 2
  • 36
  • 54
neethu K
  • 21
  • 6
  • please see the accepted answer in http://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python – nEJC Oct 17 '13 at 10:39

1 Answers1

0

You need to modify your serv cli1 and cli2 functions so they terminate themselves if a flag which you will set in your main thread is set.

piokuc
  • 25,594
  • 11
  • 72
  • 102