You are not logged in.

#1 2013-07-03 20:24:15

Super Root
Member
Registered: 2012-08-04
Posts: 23

[Python] KeyboardInterrupt - How to stop a thread?

try:

	threading.Thread(target=server.serve_forever).start()

except KeyboardInterrupt:
	
	# STOP THREAD AND TERMINATE APPLICATION

How do I do that?

I need a way to stop that thread and exit application completely.


Simplicity is prerequisite for reliability.   -- Edsger Dijkstra

Offline

#2 2013-07-03 21:45:22

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: [Python] KeyboardInterrupt - How to stop a thread?

Set the "daemon" attribute to True. The subthreads should then exit when the main thread does.

Again, please take a look through the modules in my threaded servers package that I linked in your other thread. I have likely encountered and solved many of the same problems that you will encounter.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#3 2013-07-04 16:43:06

Super Root
Member
Registered: 2012-08-04
Posts: 23

Re: [Python] KeyboardInterrupt - How to stop a thread?

[DELETED]

Found a way on my own. Thanks Xyne for your help though.

Last edited by Super Root (2013-07-04 16:58:08)


Simplicity is prerequisite for reliability.   -- Edsger Dijkstra

Offline

Board footer

Powered by FluxBB