Python Forum

Full Version: Threads in threads?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi folks.

I have an app which is part system reporting tool and part socket server. I've written this as one app as both bits are dependent.

So the app starts and creates two threads, reporter and server, both started and joined as both are no ending.

The problem I have is in the server thread, the very simple socket code creates a new thread for a client connection, perfumes a task and ends. However my line;
thread.start_new_thread(handler, (client socket, clientaddr))
throws an error saying start_new_thread doesn't exist.

It most certainly does! And until I changed this code recently to run in a thread it was working fine. So, is there any reason why I can't start a thread from a running thread that isn't main?

Thanks.
(Oct-13-2018, 09:04 PM)MuntyScruntfundle Wrote: [ -> ]thread.start_new_thread(handler, (client socket, clientaddr))
The first rule of survival in python's thread programming is to use the threading module instead of the low level _thread (or thread in previous versions) module. Change your code to use the threading module first, then if there is still an issue, post it here Wink