Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threads in threads?
#1
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.
Reply
#2
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiprocessing: Threads work well. Processes don't work. viyubu 11 1,768 Dec-03-2023, 08:50 PM
Last Post: snippsat
  What to do to stop all these threads? Valjean 3 535 Oct-02-2023, 01:50 PM
Last Post: deanhystad
  threading native_id returning same value for all threads billykid999 2 982 May-04-2023, 06:40 AM
Last Post: billykid999
  Update old Python version because of security threads SanderV 2 1,542 Jun-06-2022, 07:49 PM
Last Post: SanderV
  Closing Threads and the chrome window it spawned from Tkinter close button law 0 1,696 Jan-08-2022, 12:13 PM
Last Post: law
  [SOLVED] Help with Threads michaelserra 3 1,986 Aug-01-2021, 02:21 PM
Last Post: michaelserra
  Trying to separate a loop across multiple threads stylingpat 0 1,670 May-05-2021, 05:21 PM
Last Post: stylingpat
  Suspending worker threads olderguy 1 2,013 Apr-21-2021, 10:28 AM
Last Post: Larz60+
Thumbs Up Working with Threads Gilush 2 1,942 Feb-04-2021, 02:53 PM
Last Post: Gilush
  Terminating Subprocesses and Threads while they're calculating lvlanson 4 2,499 Oct-17-2020, 12:33 PM
Last Post: lvlanson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020