473,385 Members | 1,798 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,385 software developers and data experts.

Passing Exceptions Across Threads

Hello, I'm writing a physics simulator back-end with a built-in,
threaded server that for the moment is quite simple. I've faced a few
problems in writing this code, however, as it's the first time I've
played with threading. For the moment, everything works decently, but I
need (or rather, want) a method for passing caught exceptions in
sub-threads to the main thread to be raised there. Although this
solution isn't the only one, I feel it will be the most elegant (the
thread/class will be called inside the main module within a try/except
structure, which makes the program a bit more modular, in my opinion,
and cleaner).

Here is my code so far:
http://rafb.net/paste/results/UESOWB24.html

You can see near the top where I clumsily tried to a hack a function
into threading._MainThread, in the hopes that if it were called from a
sub-thread it would execute in the main thread. This is seemingly not
so.

Many thanks for any help.

Apr 26 '06 #1
2 1248
have you tried replacing :

main = threading._MainThread()

with

main = threading.currentThread() ?

(not sure if that will be sufficient)

Well your way to pass exception between threads looks like I would have
done myself. But I am no expert.

Have you considered using stackless Python ? It provides a much safer
and efficient threading model (thinking about your physics simulator).
Of course, if you want not to block on blocking calls (socket stuff),
real threads are a way to go.

Apr 26 '06 #2
Adam Mullins wrote:
Hello, I'm writing a physics simulator back-end with a built-in,
threaded server that for the moment is quite simple. I've faced a few
problems in writing this code, however, as it's the first time I've
played with threading. For the moment, everything works decently, but I
need (or rather, want) a method for passing caught exceptions in
sub-threads to the main thread to be raised there. Although this
solution isn't the only one, I feel it will be the most elegant (the
thread/class will be called inside the main module within a try/except
structure, which makes the program a bit more modular, in my opinion,
and cleaner).

Here is my code so far:
http://rafb.net/paste/results/UESOWB24.html

You can see near the top where I clumsily tried to a hack a function
into threading._MainThread, in the hopes that if it were called from a
sub-thread it would execute in the main thread. This is seemingly not
so.

Many thanks for any help.


The CallQueue and BackgroundCall.get_return() do that exception transfer
already by default:

http://aspn.activestate.com/ASPN/Coo.../Recipe/491281
http://aspn.activestate.com/ASPN/Coo.../Recipe/491280

-robert
Apr 26 '06 #3

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

Similar topics

1
by: Roy Smith | last post by:
What is supposed to happen when an exception is raised and not caught in a thread? The Reference Manual (section 4.2) states "When an exception is not handled at all, the interpreter terminates...
7
by: Kenny Cutter | last post by:
Hi group, I am quite new to exceptions in .NET and I am a bit confused of how to use the inner exceptions. Could anyone explain? Let's say I have a function that takes a double (X) that is not...
6
by: Garma | last post by:
According to what I have learnt so far, instantiating global objects should be the last resort. Is there any reasons why so? Sometimes some objects or their pointers have to be shared among...
7
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException...
16
by: Einar Høst | last post by:
Hi, I'm getting into the Trace-functionality in .NET, using it to provide some much-needed logging across dlls in the project we're working on. However, being a newbie, I'm wondering if some...
10
by: Cool Guy | last post by:
Consider: void Start() { if (!TryToDoSomething()) ShowErrorMessage(); }
3
by: thomson | last post by:
Hi All, Are there any sort of exceptions that cannot be caught by the Runtime, Any Insights? Thanks in Advance thomson
6
by: robert | last post by:
I get python crashes and (in better cases) strange Python exceptions when (in most cases) importing and using cookielib lazy on demand in a thread. It is mainly with cookielib, but remember the...
25
by: Denis Kukharev | last post by:
I have a problem when catching a plenty of exceptions simultaneously in different threads: the Load Average indicator exceeds 100.0 and the process seems to "hang up". I managed to simulate this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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,...
0
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...

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.