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
  Threads problem svalencic 2 507 Jan-16-2025, 04:40 PM
Last Post: svalencic
  RuntimeError: threads can only be started once Raysz 10 4,253 Nov-24-2024, 03:24 PM
Last Post: Raysz
Question parallel merge sort algorithm with threads yangg 2 1,696 Aug-24-2024, 09:36 AM
Last Post: yangg
  Seeking some script design advice... involves asyncio, threads, multiprocessing sawtooth500 1 853 Jul-05-2024, 10:39 PM
Last Post: AdamHensley
  Having difficulty with threads and input() sawtooth500 13 4,009 Jun-07-2024, 08:40 AM
Last Post: Gribouillis
  Multiprocessing: Threads work well. Processes don't work. viyubu 11 4,322 Dec-03-2023, 08:50 PM
Last Post: snippsat
  What to do to stop all these threads? Valjean 3 1,788 Oct-02-2023, 01:50 PM
Last Post: deanhystad
  threading native_id returning same value for all threads billykid999 2 3,472 May-04-2023, 06:40 AM
Last Post: billykid999
  Update old Python version because of security threads SanderV 2 2,281 Jun-06-2022, 07:49 PM
Last Post: SanderV
  Closing Threads and the chrome window it spawned from Tkinter close button law 0 2,378 Jan-08-2022, 12:13 PM
Last Post: law

Forum Jump:

User Panel Messages

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