473,322 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

question to start_new_thread 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_new_thread(self.ConnectionHandler, (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 7626
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_new_thread(self.ConnectionHandler, (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***************@engcorp.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_new_thread this:
connThread = Thread(target=self.ConnctionHandler, args=(conn,))
connThread.start()
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***************@engcorp.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_new_thread this:
connThread = Thread(target=self.ConnctionHandler, args=(conn,))
connThread.start()
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
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...
7
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...
5
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...
15
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...
3
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
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...
5
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...
1
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...
11
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.