473,769 Members | 8,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question to start_new_threa d in thread

Hi there,

I wrote a tcp server which listens on a port. When he gets a new
connection, he starts a new thread like this:
thread.start_ne w_thread(self.C onnectionHandle r, (conn,))
where conn is the socket for the connection.

After I started the server, I can see one running process under Linux,
which is ok. But once I connected to the Server, I always see two
processes where one is the parent of the other. I think this should be
normal behavier as long as the connection is established. But I also
see two processes when the connection is finished. So I thought that I
don't quit the thread for the connection correctly. Then I should see
three processes after I started a second connection, but I don't.
There are alwys just the two of them.

My question now is: does python make a thread pool where it does not
really quit the threads but instead reuses them if necessary? Or does
it need a second process to administrate threads?

bye

Thomas
Jul 18 '05 #1
3 7654
Thomas Schmid wrote:

I wrote a tcp server which listens on a port. When he gets a new
connection, he starts a new thread like this:
thread.start_ne w_thread(self.C onnectionHandle r, (conn,))
where conn is the socket for the connection.

After I started the server, I can see one running process under Linux,
which is ok. But once I connected to the Server, I always see two
processes where one is the parent of the other. I think this should be
normal behavier as long as the connection is established. But I also
see two processes when the connection is finished. So I thought that I
don't quit the thread for the connection correctly. Then I should see
three processes after I started a second connection, but I don't.
There are alwys just the two of them.

My question now is: does python make a thread pool where it does not
really quit the threads but instead reuses them if necessary? Or does
it need a second process to administrate threads?


I can't answer this other than to say stop using "thread" and start
using "threading" . If you are using "threading" and your threads stop,
they disappear as you would expect. I don't think anyone is supposed
to use "thread" anymore... and it might solve your problems.

-Peter
Jul 18 '05 #2
Peter Hansen <pe***@engcorp. com> wrote in message news:<3F******* ********@engcor p.com>...

I can't answer this other than to say stop using "thread" and start
using "threading" . If you are using "threading" and your threads stop,
they disappear as you would expect. I don't think anyone is supposed
to use "thread" anymore... and it might solve your problems.

-Peter


I tried it out and wrote instead of thread.start_ne w_thread this:
connThread = Thread(target=s elf.ConnctionHa ndler, args=(conn,))
connThread.star t()
The result is exactly the same. First, I see only one process. But as
soon as I connect to the server, there are two processes which always
are there even if I disconnect. But still, there are never more then
two processes. I think the other process is a controle thread because
I found this in the documentation:
"There is a ``main thread'' object; this corresponds to the initial
thread of control in the Python program. It is not a daemon thread."

bye

Thomas
Jul 18 '05 #3
Thomas Schmid wrote:

Peter Hansen <pe***@engcorp. com> wrote in message news:<3F******* ********@engcor p.com>...

I can't answer this other than to say stop using "thread" and start
using "threading" . If you are using "threading" and your threads stop,
they disappear as you would expect. I don't think anyone is supposed
to use "thread" anymore... and it might solve your problems.

-Peter


I tried it out and wrote instead of thread.start_ne w_thread this:
connThread = Thread(target=s elf.ConnctionHa ndler, args=(conn,))
connThread.star t()
The result is exactly the same. First, I see only one process. But as
soon as I connect to the server, there are two processes which always
are there even if I disconnect. But still, there are never more then
two processes. I think the other process is a controle thread because
I found this in the documentation:
"There is a ``main thread'' object; this corresponds to the initial
thread of control in the Python program. It is not a daemon thread."


So, logically, one would conlude that your thread never exits, even when
you disconnect. You'd better post code, or start sticking print statements
inside until you discover what is actually happening in your code.

Or replace the thread target with a function that does a simple time.sleep()
and observe the results. You should see the process exit, which ought to
prove to you that the problem is with your specific server code, and not
threads in Python.

-Peter
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2348
by: Mike Zupan | last post by:
I wrote this simple threading app using pygame. I'm looking to load a movie via mplayer in full screen mode and have all my events be sent to my python app and not mplayer. When my mouse is over the python app it handles the events but when its over the mplayer window it handles mplayer only. I'm new to threads so if anyone has a really great tutorial let me know. My book didn't go into great detail import pygame
7
10576
by: Brian Kelley | last post by:
I am trying to use threads and mysqldb to retrieve data from multiple asynchronous queries. My basic strategy is as follows, create two cursors, attach them to the appropriate databases and then spawn worker functions to execute sql queries and process the results. This works occasionally, but fails a lot taking python down with it. Sometimes it also loses connection to the database. Sometimes I get an error, "Commands out of sync; ...
5
2716
by: Jon Perez | last post by:
Running the following under Linux creates 3 processes instead of 2. Once the started thread exits, 2 processes still remain. Why? import thread from thread import start_new_thread def newthread(): print "child"
15
1596
by: Valkyrie | last post by:
Refering to the following codes I found, there is nothing displayed in the console, may I ask why? def thrd(param): # the thread worker function print "Received",param import thread for i in range(5): # start five threads passing i to each one thread.start_new_thread(thrd,(i,))
3
4948
by: Konstantin Veretennicov | last post by:
Hi, Just curious: >>> import thread >>> help(thread.start_new_thread) . . . start_new_thread(function, args) . . . Second argument is mandatory. Is it incidental or for a reason?
14
1363
by: ed | last post by:
this script should create individual threads to scan a range of IP addresses, but it doesnt, it simple ... does nothing. it doesnt hang over anything, the thread is not being executed, any ideas anyone? ---------- import socket import threading import traceback
5
2142
by: Richard P | last post by:
I need some help on timers. My app is asp.net 1.1 website running in a shared hosting environment with a third-party service provider. I currently request and cache 20 - 40 remote RSS feeds. When a user requests the page, the app first tries to retrieve a feed from cache, if the feed has expired, it goes off and request the file from the web. If create a CacheItemRemovedCallback for each item to automatically re-request an expired...
1
3714
by: Luxore | last post by:
Hello, I am trying to create threaded python project and I'm running into some weird Python variable scoping. I am using the "thread" module (I know, it's old and I should be using threading)... but for example: <code> import thread
11
4269
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate threads of a multithreaded program using embedded SQL. Since the threads do not need to share transaction scopes, the sqleAttachToCtx family of APIs do not seem to be necessary. <quote> In the default implementation of threaded applications against...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.