Dear all,
Following are some codes:
from myClass import * # some user define classes, which will catch
the exception within its function
thread_function ():
myClass myclass
while (1):
returnValue = myclass.myfunct ion();
print "Return Value %s" % returnValue
#... cont' to do something
# main
thrd = threading.Threa d(None,thread_f unction,"thread _function")
thrd.setDaemon( True)
thrd.start()
#... cont' to do other thing
'myClass.myfunc tion()' will return some value (used 'return') when
caught exceptions and let the 'thread_functio n()' handle the following.
But now found that after 'myClass.myfunc tion()' return, both thread
program and main program will exit, when i prefer it will cont' to run.
is it the default behavior of thread return? Thank a lot 2 1696
> is it the default behavior of thread return? Thank a lot
No.
First of all: your code is clearly _not_ exposing the described behaviour -
you talk about exception handling, but there is none done. And you don't
say anything about what your doing in your "cont'" parts.
If code run in a thread throws an exception that is not handled, the thread
will die.
The program will terminate when the main thread terminates and all other
threads that have setDaemon(False ) are terminated. If all the threads
(except main) have setDaemon(True) (as yours has), the program will end
immediately after the main thread terminated.
Read the threading modules docs.
--
Regards,
Diez B. Roggisch
Sorry that i had't show my code clearly.
The exception try and catch at the module function (i.e.
myClass.myfunct ion(), which like:
#### start code within myClass.py ####
def myfunction(self , dbconnection):
sql_query= 'update table set col=value'
try:
dbconnection.qu ery(sql_query)
result = dbconnection.st ore_result()
tuple_list = result.fetch_ro w(0,0)
except MySQLError (errno, strerror):
print "MySQLError , errno: %s, strerror: %s" % (errno, strerror)
return 11
except (errno, strerror): # catch all
print "General Error, errno: %s, strerror: %s" % (errno, strerror)"
return 21
#### end code within myClass.py ####
and let main thread function (thread_functio n()) to handle the sub
thread function by its return value (mainly are update database,
printing message and continuous to run).
Should the exception catch at main thread function rather than
class function?
Thank for helping.
return 1 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bruce Bon |
last post by:
The class below is intended to play a Sun audio file (.au) in the
background while the main thread, which is servicing a GUI, continues
without impact. It doesn't work. For a sound file that takes 3-5
seconds to play, the main thread hangs for that long. I have run this
many times, with changes in printouts and insertion of strategic
sleeps to try to make sure that the player thread gives up control,
but apparently the call to...
|
by: phil |
last post by:
And sorry I got ticked, frustrating week
>And I could help more, being fairly experienced with
>threading issues and race conditions and such, but
>as I tried to indicate in the first place, you've
>provided next to no useful (IMHO) information to
>let anyone help you more than this
This is about 5% of the code.
Uses no locks.
|
by: Alexander |
last post by:
Hi, I have written a program that takes on some operations much more
time than I expected. As I have seen users clicking wildly on the
screen to make something happen, I want to follow the microsoft
principles: always show them something ;)
First I made up a little status dialog containing a gif image to show
a little animation and a TextBox for a changing status message during
the work of the main program.
Just showing the dialog box...
|
by: Tom |
last post by:
First of all, is it 'legal' (i.e. thread-safe) to pass events back from
a worker thread to the main thread? I.E. Can one put PUBLIC EVENT XYZ
in their worker thread and then raise that event for processing back in
the main thread? I believe this is OK, but I want to check first...
Secondly, if this is 'legal', what happens in the following scenario:
Lets say that in my main (Win Form) program/thread I spawn two worker
threads. Thread one...
|
by: Andrew Bullock |
last post by:
Hi,
I'm using a second thread within my program to do some long
calculations, without locking up the UI:
worker = new Thread(new ThreadStart(myClass.Run));
worker.Start();
I want to be able to pause the calculating, so I'm using
| |
by: fiefie.niles |
last post by:
I am having problem with thread. I have a Session class with public
string variable (called Message) that I set from my Main program. In
the session class it checks for the value of Message while inside it's
"read loop" waiting for data from the client. I find that many times
while inside the "read loop" it missed many of the value that was
assigned to the public Message variable.
For example, the main program send number 1 thru 100, but...
|
by: zxo102 |
last post by:
Hi,
I am doing a small project using socket server and thread in python.
This is first time for me to use socket and thread things.
Here is my case. I have 20 socket clients. Each client send a set
of sensor data per second to a socket server. The socket server will
do two things: 1. write data into a file via bsddb; 2. forward the data
to a GUI written in wxpython.
I am thinking the code should work as follow (not sure it is
feasible)...
|
by: nospam |
last post by:
Hi all.
I have encountered a "Cross-thread operation not valid" error in a
test program I created and although I have came up with a solution I
don't like the performance of the program.
I hope perhaps some experts here can help me out.
Here is what my program consists of:
1) A form containng several tabs, one of which contains a ListView
|
by: Brad Walton |
last post by:
Hello. First post, but been doing a bit of reading here. I am working on a
project in Java, but decided to switch over to C# after seeing some of the
additional features I can get from C#. One of the big changes I want to make
is event-driven code (rather than the linear flow I had in Java). I have
spent a week or so searching Google, talking to a couple of programming
friends, and just chewing on it in my brain. I think I have an ok handle...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |