473,779 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

idea: add an asynchronous exception class

I'd like to suggest adding a builtin abstract class to Python called
AsynchronousExc eption, which would be a subclass of Exception. The
only asynchronous exception I can think of right now is
KeyboardInterru pt, so KeyboardInterru pt would become a subclass of
AsynchronousExc eption instead of being a direct subclass of Exception.
There's been talk of adding ways of raising asynchronous exceptions
across threads from user code, so those exceptions would also be
subclassed from AsynchronousExc eption.

The reason for wanting this is the common idiom

try:
run_parrot_code () # might raise ParrotException
except ParrotException :
pass # or do some stuff
except IOError:
pass
except:
# run_parrot_code raised something unexpected
print 'unexpected exception'
raise

The catchall except: block captures not only unexpected exceptions
raised from the dynamic scope of the try: block, but also any
asynchronous exception that might be raised. It should have a way to
distinguish between those two cases, i.e. by checking whether the
caught exception is an instance of AsynchronousExc eption. That's
better than checking for all known asynchronous exceptions explicitly
and then having the code break when a new such exception gets added.

Catchall "except" blocks are generally frowned on because of this
issue but they're used all over the place anyway.

The suggestion above is extremely simple to implement but there might
be better ways to solve the problem.
Mar 4 '06 #1
8 1358
On Fri, 03 Mar 2006 22:31:49 -0800, Paul Rubin wrote:
I'd like to suggest adding a builtin abstract class to Python called
AsynchronousExc eption, which would be a subclass of Exception.


[snip rationale]

+1 on this.

--
Steven.

Mar 4 '06 #2
Paul Rubin wrote:
I'd like to suggest adding a builtin abstract class to Python called
AsynchronousExc eption, which would be a subclass of Exception. The
only asynchronous exception I can think of right now is
KeyboardInterru pt, so KeyboardInterru pt would become a subclass of
AsynchronousExc eption instead of being a direct subclass of Exception.


PEP 348 addresses this by moving special exceptions out of the
Exception hierarchy:

http://www.python.org/peps/pep-0348.html

</F>

Mar 4 '06 #3
"Fredrik Lundh" <fr*****@python ware.com> writes:
PEP 348 addresses this by moving special exceptions out of the
Exception hierarchy:

http://www.python.org/peps/pep-0348.html


I see that suggestion was rejected (it needed changing the semantics
of "except:"). Also, PEP 348 was rejected and is a huge, complex
reorganization of the whole exception system. This is cited:

http://mail.python.org/pipermail/pyt...st/055423.html

but it talks about distinguishing terminating from non-terminating
exceptions, whatever that means. (Won't any uncaught exception like
ValueError terminate the program)?

I realize now that exceptions arising from signals are also asynchronous
(http://docs.python.org/lib/module-signal.html). So that's another
place where we'd see user-defined asynchronous exceptions: signal
handlers should raise them instead of raising ordinary exceptions.
Mar 4 '06 #4
On Sat, 04 Mar 2006 08:41:48 +0100, Fredrik Lundh wrote:
Paul Rubin wrote:
I'd like to suggest adding a builtin abstract class to Python called
AsynchronousExc eption, which would be a subclass of Exception. The
only asynchronous exception I can think of right now is
KeyboardInterru pt, so KeyboardInterru pt would become a subclass of
AsynchronousExc eption instead of being a direct subclass of Exception.


PEP 348 addresses this by moving special exceptions out of the
Exception hierarchy:

http://www.python.org/peps/pep-0348.html


The PEP has been summarily rejected, perhaps because it was too broad in
the changes it suggested.

--
Steven.

Mar 4 '06 #5
Paul Rubin wrote:
"Fredrik Lundh" <fr*****@python ware.com> writes:
PEP 348 addresses this by moving special exceptions out of the
Exception hierarchy:

http://www.python.org/peps/pep-0348.html


I see that suggestion was rejected (it needed changing the semantics
of "except:"). Also, PEP 348 was rejected and is a huge, complex
reorganization of the whole exception system.


The relevant part of PEP 348 survived as PEP 352.

http://www.python.org/peps/pep-0352.html

--
Robert Kern
ro*********@gma il.com

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Mar 4 '06 #6
"Paul Rubin" <http://ph****@NOSPAM.i nvalid> wrote in message
news:7x******** ****@ruckus.bro uhaha.com...
"Fredrik Lundh" <fr*****@python ware.com> writes:
PEP 348 addresses this by moving special exceptions out of the
Exception hierarchy:

http://www.python.org/peps/pep-0348.html


I see that suggestion was rejected (it needed changing the semantics
of "except:"). Also, PEP 348 was rejected and is a huge, complex
reorganization of the whole exception system. This is cited:

http://mail.python.org/pipermail/pyt...st/055423.html

but it talks about distinguishing terminating from non-terminating
exceptions, whatever that means. (Won't any uncaught exception like
ValueError terminate the program)?


I guess it means the following:

"Terminatin g exceptions" are exceptions that
terminate the *thrower* of the exception.
"Non-terminating exceptions" are exceptions
that might allow the thrower to resume
(provided the catcher does *not* decide
to unwind the thrower's stack frame - and
possibly some other frames as well...).
So non-terminating exceptions allow the
thrower to offer the catcher a choice
between terminating the thrower or having
him try harder (until he possibly throws
yet another, but maybe this time terminating
exception that does not allow the catcher to
ask for resumption of the throwing code).

So what's terminated (or not terminated)
here is not the program but merely the
code that throws an exception.
VAX/VMS had such a non-terminating exception
handling mechanism, for example.

Regards,
Christian
Mar 4 '06 #7
"Christian Stapfer" <ni*@dev.nul> writes:
I guess it means the following:

"Terminatin g exceptions" are exceptions that
terminate the *thrower* of the exception.


Are you sure? I didn't read it that way. I'm not aware of there ever
having been a detailed proposal for resumable exceptions in Python,
though the gurus would know better than I do whether there's been one.

Mar 4 '06 #8
"Paul Rubin" <http://ph****@NOSPAM.i nvalid> wrote in message
news:7x******** ****@ruckus.bro uhaha.com...
"Christian Stapfer" <ni*@dev.nul> writes:
I guess it means the following:

"Terminatin g exceptions" are exceptions that
terminate the *thrower* of the exception.


Are you sure?


Am I sure? - Well no! As I wrote: this is
just my *guess*.
But if certain terms are not explained
upfront then, I assume, the writer must have
had some "well known" interpretation in mind.
These two alternatives, the abortion and
the resumption model of exception handling,
are certainly that: "well known". Hence
my guess...

Regards,
Christian
Mar 5 '06 #9

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

Similar topics

1
2841
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...
3
1206
by: Anders Both | last post by:
Does someone know´s about using threads and/or asynchronous programming inside asp.net (inside the asp.net process). I am here not speaking about the thing that the IIS makes new threads for each request, but about starting a thread inside the asp.net process. I am making big use of this thing in my applikation, but I have the problem that when exceptions/errors uccur no message is bein showed. When VS is running a wery undetaild message...
7
2388
by: Colin | last post by:
I'm writing a little console socket server but I'm having some difficulty. Can I ask your advice - where is the best place to get some help on that topic? It would be nice if some people who knew what they were doing could take a look at my code and tell me where and why I'm going wrong. Any suggestions of groups or forums?
2
6879
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless there is a problem with the connection. I need to know which client has sent the incoming data as each client has its own buffer on my "server" app. I am using the standard asynch socket code from MSDN to listen for connections and they...
7
9716
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason for this being to stop the user thinking the application has frozen when in fact it is just waiting for a long SP to complete. Another reason for doing it like this is that I also have had a problem in the past where the SP takes longer than the...
0
1757
by: Bishoy George | last post by:
Hi, I have a asp.net 2.0 web application. I want to implement the asynchronous model through http handler in web.config ------------------------------------------------------------------------------------------------------------------------- My web.config file: ---------------------
6
7007
by: Pat B | last post by:
Hi, I'm writing my own implementation of the Gnutella P2P protocol using C#. I have implemented it using BeginReceive and EndReceive calls so as not to block when waiting for data from the supernode. Everything I have written works fine sending and receiving uncompressed data. But now I want to implement compression using the deflate algorithm as the Gnutella protocol accepts: Accept-Encoding: deflate Content-Encoding: deflate in the...
5
8241
by: raghubr | last post by:
Hi all, Can any one pls guide me through..I need to transfer the file from server to client and client to server using sockets in an Asynchronous mode so this file transfer doesn't hinder the common process of connecting and of the server and client... here is the code i am trying to implement. this code snippet is for message transfer only for multiple clients. /////////////////////////////file receive method when sent from...
0
1307
by: cmrhema | last post by:
Hi, We have an asynchronous server socket program, which works fine BUT, when due to some circumstances, I receive null data or blank data, the server goes to infinite loop Here is the code namespace SocketServer { public class StateObject //class created to clear the duplicate records { // Client socket.
0
9632
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
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10302
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
10136
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
10071
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
8958
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
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
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
3631
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.