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

Radical: listing decorators compared to atexit function registration

Still looking for a unifying concept ;-)

It struck me that

@deco1
@deco2
def foo():pass

uses '@' to register at-next-name-binding processing in a way similar to atexit's
registering of processing to happen at ('@' ;-) exit.

IOW, it is setting up processing for an event (synchronous in this case)
that is expected to happen in the future.

I like that meaning of '@' -- i.e., @event_handler_defining_expression seems like
a nice general reading of an 'at'-symbol.

In the case of function decoration, the event is implicitly the completion of the
execution of next-in-code-sequence function definition, intercepting
just before name-binding. And a chain of interceptions works in order.

In the case of current decorators, deco1 etc must be expressions resulting in
functions. By default, the functions are hooked into a chain of at-next-name-binding
processing that gets triggered by the def name binding. This is the current use case.

However, the broader concept is for @expression to cause registration of a generalized
event handler into an event recognition/handling mechanism. The concept can be embellished
with one-shot vs repeated and with or without timeout, multiple events, etc., but leave
that for later, so long as the door is not closed to it.

If @expression evaluating to a function defaults to a certain meaning, it should be
possible to spell it out using a compatible general and full spelling. OTTOMH ISTM
that the natural alternative to returning a function or ordinary callable would be
to return an object that the infrastructure would recognize and register into the
appropriate alternative event-handling place.

One way would be if the object were marked in a similar way that an object gets
marked as a descriptor (which happens with a __get__ method etc). Perhaps __handler__ ?
Thus you could write a class with a __handler__ method and instantiate it with info
re what event to recognize and other particulars. Then decorator syntax spelled out
might look (in concept, this is not a design spec ;-) like:

@my_next_binding_handler(func=deco1, event='before_next_local_binding')
@my_next_binding_handler(func=deco2, event='before_next_local_binding')
def foo():pass

Note that you could potentially define object attribute access events and have another way
to define properties, if you passed info to your handler constructor specifying name and
namespace. Obviously the infrastructure would have to grow some event-handling and
relevant registration etc magic.

This is essentially a push to start thinking about bringing generalized event-driven
programming nicely into python. I'm suggesting that decorators can be seen as special
one-shot event handlers for a local binding event. A GUI is obviously a source of many
user action events, and a way to say @mouseover('this','that') to instantiate and
register some code might be neat. Ditto for i/o related events. This brings in thread
issues though, and event queuing etc. But that can be deferred. We can just deal with
synchronous events for the time being. Hm... recoverable exceptions anyone ;-)

OTOH, this may all just be a symptom of attempted personal stress escape ;-)

Regards,
Bengt Richter
Jul 18 '05 #1
0 1493

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

Similar topics

12
by: Colin J. Williams | last post by:
Christopher T. King suggested that "we're trying to kill too many birds with one stone". ...
14
by: Arien Malec | last post by:
Apologies for feeding the fire, when we are rallying around a consensus, but I've been concerned about the clash between syntax and semantics, and I've finally reached a mini-epiphany: The...
0
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
3
by: Serve Laurijssen | last post by:
Does the C++ standard say whether destructors are called before or after "atexit" functions are called. Or is nothing said about that?
2
by: Steve Lambert | last post by:
Hi, Is it possible for the functions registered with atexit() to have access to parameter to exit i.e EXIT_SUCCESS or EXIT_FAILURE? I'd like to register a set of routines to be executed on...
20
by: Aek | last post by:
We recently moved our large codebase over from VS7 to 8 and found that we now get access violations in atexit calls at shutdown when debugging the application in VS2005. This occurs in static...
2
by: Christopher Pisz | last post by:
I am attempting to write a "Phoenix Singleton" using the book "Modern C++ Design" by Alexandrescu I do not understand his use of... #ifndef ATEXIT_FIXED std::atexit(Kill); #endif ....in the...
18
by: lak | last post by:
I am studying the Advanced programming in the unix environment. There they says that we can register upto 32 functions with atexit(). Why that is limited to 32 functions? can any one tell the...
0
by: Scott SA | last post by:
Hi, I've been trying to wrap my head around decorators and in my trails found avery recent article on Linux Mag's website. I didn't see a post here regarding this article and feel it is worth...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.