473,698 Members | 2,556 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about thread

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",para m

import thread
for i in range(5): # start five threads passing i to each one
thread.start_ne w_thread(thrd,( i,))

Thanks in advance
Jul 18 '05
15 1586
On Sat, 2004-11-20 at 04:56, Jarek Zgoda wrote:
Are you sure? I keep observing that child threads continue its execution
until completion even if I do nothing in main thread. Consider this example:


Well, I'm very far from an expert, but I've also experienced the
poster's reported behaviour even with quite simple programs. I'm
surprised to hear that the initially described behaviour isn't always
the case, and would be interested in knowing more about when it is, and
is not, generally encountered.

--
Craig Ringer

Jul 18 '05 #11
Diez B. Roggisch wrote:
Even after printing "finished creating threads" all spawned threads
continue its execution up to final "thread nnnn is being destroyed", so
I think there's no need to take any special action (unless it's Python
on iSeries, buy this is another story) to wait for completion.
The OP used the module "thread", while you used "threading" and didn't set
setDaemon(False ). Then python waits until all threads are finished.


Well... I was bit too fast in replying. ;)
From the thread module docs:

When the main thread exits, it is system defined whether the other threads
survive. On SGI IRIX using the native thread implementation, they survive.
On most other systems, they are killed without executing try ... finally
clauses or executing object destructors.


So it looks that using threading should be preferred over using thread,
as presented example works identically on Windows and on linux (it
doesn't work on AS/400, though...).

--
Jarek Zgoda
http://jpa.berlios.de/ | http://www.zgodowie.org/
Jul 18 '05 #12
Jarek Zgoda wrote:
You need to cause the main thread to wait on the child threads until
they've all finished, otherwise - as Peter Hickman just mentioned - your
script will terminate and all threads will end. Ten seconds on Google
found this:

http://www.faqts.com/knowledge_base/view.phtml/aid/1364


Are you sure? I keep observing that child threads continue its execution
until completion even if I do nothing in main thread. Consider this
example:


You are using the real thing - the highlevel threading.Threa d class - not
the underlying thread.start_ne w_thread() function.
The threading module creates a _MainThread (a Thread subclass) instance that
registers itself as an atexit handler and waits for the other (non-demon)
Thread instances to terminate.

Failure-to-provide-the-source-code-will-ultimately-work-against
-companies-sitting-on-a-pile-of-crap-patents-ly yours

Peter

Jul 18 '05 #13
I just looked up for the keywords "python thread example" in google and few
useful links are retrieved. It seems that most of the examples are too complicated.

Scott David Daniels wrote:
Valkyrie wrote:
Thank you for your advice. I have quite seriously searched for it in fact, but
just without the luck on finding such article...


Can you suggest where this information might have shown up
that you would have found it? If so, you may want to submit
a documentation bug or patch request. That is, repay the
group by making it more likely that the next person with your
problem finds their answer on their own.

--Scott David Daniels
Sc***********@A cm.Org

Jul 18 '05 #14
So may I ask is threading do exactly the same in terms of functionalities as
those in thread?
Jarek Zgoda wrote:
Diez B. Roggisch wrote:
Even after printing "finished creating threads" all spawned threads
continue its execution up to final "thread nnnn is being destroyed", so
I think there's no need to take any special action (unless it's Python
on iSeries, buy this is another story) to wait for completion.

The OP used the module "thread", while you used "threading" and didn't
set
setDaemon(False ). Then python waits until all threads are finished.

Well... I was bit too fast in replying. ;)
From the thread module docs:

When the main thread exits, it is system defined whether the other
threads
survive. On SGI IRIX using the native thread implementation, they
survive.
On most other systems, they are killed without executing try ... finally
clauses or executing object destructors.

So it looks that using threading should be preferred over using thread,
as presented example works identically on Windows and on linux (it
doesn't work on AS/400, though...).

Jul 18 '05 #15
Valkyrie wrote:
So may I ask is threading do exactly the same in terms of functionalities
as those in thread?


Yes, even more than thread. threading is considered the somewhat "better"
interface, as it exposes its funtionality in an objectorientied fashion -
and in this case, that's actually better :)
--
Regards,

Diez B. Roggisch
Jul 18 '05 #16

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

Similar topics

5
2136
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...
11
4261
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...
3
1992
by: Jon Pope | last post by:
I've got a basic question about threading which I'm hoping someone here will be able to answer: Let's say my calling CallingClass has instantiated and started a worker thread. When my worker thread has completed, it fires an event which CallingClass has an event handler listening for. My question is this: in which thread is that event handler operating? The worker's or CallingClass's? The issue I'm running into is that if I include...
1
2837
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from remote server and display this info on the UI. From doing some research, I know that the way my implementation works today is not thread-safe, because essentially my worker thread updates the UI, which is BAD. So, here I am trying to figure out how...
18
2062
by: Nick Z. | last post by:
I am writing a reusable class for logging. My goal is to make it as fast and as robust as possible, while keeping memory usage to the lowest. All members are static. For some reason I'm stuck on the following design question. Obviously you need a stream to write the log file. Should this stream be created every time the log needs to be written, or should the stream be a member variable of the logging class and only be opened and closed...
10
3453
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read somewhere that each folder under the "web site" is compiled in separate assembly. I however, did not find that the "web site" creation in vs.net 2005 created any AssemblyInfo.cs file.
2
1663
by: SStory | last post by:
Here is the situation. I want to display Icons, Type of file etc from a file extension. Upon initial program load I may only need icons for certain files. But other operations will require showing all filetypes and icons. I have an object that has extension, desc (like Word Document) and then icon, which is nothing to start with. I have a collection object of these and when it is initialized it goes to
10
3719
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server Error in '/QuickStartv20' Application. -------------------------------------------------------------------------------- Configuration Error Description: An error occurred during the processing of a configuration file
2
1416
by: archana | last post by:
Hi all, I don't have much of knowledge about threading. I have on .net application where in main i am starting one secondary thread. like
4
3601
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket client and asynchronous socket server example code provided in the .NET framework developers guide is a great start but I have not dealt with sockets before and I am struggling with something. From what I can tell the sample server code ...
0
8683
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
9170
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...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
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
8871
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
7739
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...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.