473,407 Members | 2,314 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,407 software developers and data experts.

How should threads be terminated? (related to 'Help with thread related tracebacks')

Hi all,

This is related to an earlier post 'Help with thread related
tracebacks'...for which I have had no feedback yet :-(

How should a thread complete i.e. how should it exit?
Reading the python online docs one gets the idea that simply returning is
OK - but I'm not sure.
Is it ok to do a sys.ext()? Use 'return' or just let them run out with no
'return' ???

thanks.
Jul 19 '05 #1
7 1772
Hi Maxwell,

Yes, to terminate a thread in Python early, use the following:

import sys; sys.exit(0)

This kills the particular thread without wiping out the entire Python
application.

Hope this helps,

Brian :-)
---
Maxwell Hammer wrote:
Hi all,

This is related to an earlier post 'Help with thread related
tracebacks'...for which I have had no feedback yet :-(

How should a thread complete i.e. how should it exit?
Reading the python online docs one gets the idea that simply returning is
OK - but I'm not sure.
Is it ok to do a sys.ext()? Use 'return' or just let them run out with no
'return' ???

thanks.

Jul 19 '05 #2
see http://aspn.activestate.com/ASPN/Coo...n/Recipe/65448 for a
useful recipe on how to do threading

Jul 19 '05 #3
Here's a site that provides an easy, *beginners* example of how to do
threading. You might find this useful too... :-)

http://www.codesampler.com/python.htm
(Look for the "Spawning Threads" section.)

Brian
---
wi******@hotmail.com wrote:
see http://aspn.activestate.com/ASPN/Coo...n/Recipe/65448 for a
useful recipe on how to do threading

Jul 19 '05 #4
Maxwell Hammer wrote:
This is related to an earlier post 'Help with thread related
tracebacks'...for which I have had no feedback yet :-(
If the question was well formulated, and it's been more than a couple of
days, you should consider reposting. It's very unusual for a post with
such a subject (if it was a clear question) to get _no_ feedback around
here.
How should a thread complete i.e. how should it exit?
As with any function, just return...
Reading the python online docs one gets the idea that simply returning is
OK - but I'm not sure.
Is it ok to do a sys.ext()? Use 'return' or just let them run out with no
'return' ???


sys.exit() merely raises a SystemExit exception. In the main thread
this will terminate the application (assuming no non-daemon threads are
still running), while in a non-main thread it should simply be ignored.

If you aren't trying to exit from a function call within the thread,
using "return" or just falling off the end of the run() method (if
you've subclasses Thread) or the target function (if you used the
"target=xxx" approach) is quite sufficient and acceptable.

Note that "return" is identical to "return None" which is identical to
just falling off the end of a function in Python. Some might consider a
simple unadorned "return" to be the most expressive and readable.

-Peter
Jul 19 '05 #5
On Thu, 16 Jun 2005 16:20:23 -0400, Peter Hansen wrote:
Maxwell Hammer wrote:
This is related to an earlier post 'Help with thread related
tracebacks'...for which I have had no feedback yet :-(


If the question was well formulated, and it's been more than a couple of
days, you should consider reposting. It's very unusual for a post with
such a subject (if it was a clear question) to get _no_ feedback around
here.


Fair enough. The question is not expressed clearly for others. Do you have
any suggestions as to how to describe the problem clearer?

I can think of no other way but to say I have an app that when I terminate
it, completes ok, However the last thing that happens before the shell
prompt returns is that there is a traceback *within* python.
(The actual post goes into more details of course.)

I just took a guess that it is *thread* related from the output of the
traceback. I'm still learning python, so how could one pose the problem
*clearer*?

And thanks for the feedback regarding threads, by the way.
Max

Jul 19 '05 #6
Thanks Brian & Martin for the links.
I actually found another good one:
http://linuxgazette.net/107/pai.html

Cheers.
Jul 19 '05 #7
Maxwell Hammer wrote:
On Thu, 16 Jun 2005 16:20:23 -0400, Peter Hansen wrote:
If the question was well formulated, and it's been more than a couple of
days, you should consider reposting. It's very unusual for a post with
such a subject (if it was a clear question) to get _no_ feedback around
here.
Fair enough. The question is not expressed clearly for others. Do you have
any suggestions as to how to describe the problem clearer?


I hope you didn't get the impression I was criticizing. I don't recall
your post at all, and definitely wasn't suggesting that it was unclear,
merely asking you to verify that it was and, if not, rewrite it upon
reposting.

As for suggestions to make it clearer: I can't make any without digging
back for your previous posting. I generally don't take the time to do
that since older messages are often gone from my server very quickly,
and I don't like spending time digging around on Google Groups to find
it. Sorry, it's just one of my approaches to conserving my own time,
selfishly.
I can think of no other way but to say I have an app that when I terminate
it, completes ok, However the last thing that happens before the shell
prompt returns is that there is a traceback *within* python.
(The actual post goes into more details of course.)
This sounds very much like the problem where, during the interpreter
shutdown, all globals in all modules are rebound to None, but if daemon
threads are still running they will quickly crash as a result and raise
exceptions, usually referring to AttributeErrors where "None" doesn't
have an attribute of a particular kind, usually the name of a method.

If I'd seen your post, I would probably have responded with as much at
the time. If you do a Google Groups search for some of those keywords
and my name, you'll certainly find a half dozen other threads where
someone else asked a similar question, even if I missed your post.
I just took a guess that it is *thread* related from the output of the
traceback. I'm still learning python, so how could one pose the problem
*clearer*?

And thanks for the feedback regarding threads, by the way.


No problem. And if this post didn't help, please do repost the whole
original question so I can see it again, and those who read the group
via the mailing list will get a fresh email, etc...

-Peter
Jul 19 '05 #8

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

Similar topics

5
by: Ralph Sluiters | last post by:
Hi, i've got a small problem with my python-script. It is a cgi-script, which is called regulary (e.g. every 5 minutes) and returns a xml-data-structure. This script calls a very slow function,...
3
by: Maxwell Hammer | last post by:
An application I am developing executes many threads and then has a "monitor" part that waits for certain events. One of these events causes the application to have to shutdown. On shutdown the...
6
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
1
by: John | last post by:
If my main UI thread starts a worker thread, who starts its own worker thread. So if i just close my app, in the closing event i can kill the thread the UI thread starts. but how can i kill the...
8
by: Martin Maat | last post by:
I am puzzled. I have this object that uses a thread. The thread is encapsulated by the object, the object has Start and Stop methods to enable the client to start or stop the thread. I found...
15
by: Bryce K. Nielsen | last post by:
I have an object that starts a thread to do a "process". One of the steps inside this thread launches 12 other threads via a Delegate.BeginInvoke to process. After these 12 threads are launched,...
2
by: jgbid | last post by:
Hi, I'm trying to build an IP Scanner inc c# for a specific port (80) and for specific IP Ranges. For example 24.36.148.1 to 24.36.148.255 My first step was to use TcpClient, but there are...
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
23
by: =?GB2312?B?0rvK18qr?= | last post by:
Hi all, Recently I had a new coworker. There is some dispute between us. The last company he worked for has a special networking programming model. They split the business logic into...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.