Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Do not use the blue keys on this terminal.


devel / comp.lang.python / Re: Register multiple excepthooks?

SubjectAuthor
o Re: Register multiple excepthooks?2QdxY4RzWzUUiLuE

1
Re: Register multiple excepthooks?

<mailman.188.1659611624.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19094&group=comp.lang.python#19094

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: 2QdxY4Rz...@potatochowder.com
Newsgroups: comp.lang.python
Subject: Re: Register multiple excepthooks?
Date: Thu, 4 Aug 2022 06:13:28 -0500
Lines: 50
Message-ID: <mailman.188.1659611624.20444.python-list@python.org>
References: <25320.3769.224412.136125@ixdm.fritz.box>
<DB6PR01MB3895BEDFCE37B51C1C470113839F9@DB6PR01MB3895.eurprd01.prod.exchangelabs.com>
<Yuup2A8vqJGL2rDD@anomaly>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de rrxzahon1y5c9WvrrXgncAvEj/bS9KCj+32vWCeM8BqQ==
Return-Path: <2QdxY4RzWzUUiLuE@potatochowder.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.020
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'def': 0.04; 'fairly':
0.05; 'exit': 0.07; 'received:78': 0.09; 'coding': 0.13; '(b)':
0.16; '+0200,': 0.16; 'both.': 0.16; 'else?': 0.16; 'framework.':
0.16; 'from:addr:2qdxy4rzwzuuilue': 0.16;
'from:addr:potatochowder.com': 0.16; 'list()': 0.16;
'received:136.243': 0.16; 'received:172.58': 0.16;
'received:78.46': 0.16; 'received:78.46.172': 0.16;
'received:78.46.172.2': 0.16; 'received:sslproxy05.your-
server.de': 0.16; 'received:www458.your-server.de': 0.16;
'received:your-server.de': 0.16; 'standard,': 0.16; 'toolbox,':
0.16; 'wrote:': 0.16; 'to:addr:python-list': 0.20; 'received:de':
0.23; 'register': 0.25; 'library': 0.26; 'object': 0.26;
'function': 0.27; 'error': 0.29; 'program': 0.31; 'think': 0.32;
'received:136': 0.32; 'but': 0.32; "i'll": 0.33; 'there': 0.33;
'header:In-Reply-To:1': 0.34; 'functions': 0.36; 'could': 0.38;
'something': 0.40; 'try': 0.40; 'skip:o 10': 0.61; 'come': 0.62;
'follow': 0.62; 'skip:o 20': 0.63; 'skip:m 20': 0.63; 'skip:r 20':
0.64; 'personal': 0.64; 'your': 0.64; 'upon': 0.64; 'top': 0.65;
'improve': 0.66; 'refine': 0.69; 'season': 0.69; 'too.': 0.70;
'charset:iso-8859-1': 0.73; 'discover': 0.80; '(c)': 0.81;
'names,': 0.81; 'minimalist': 0.84; 'non-english': 0.84;
'really.': 0.84
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <DB6PR01MB3895BEDFCE37B51C1C470113839F9@DB6PR01MB3895.eurprd01.prod.exchangelabs.com>
X-Authenticated-Sender: 2QdxY4RzWzUUiLuE@potatochowder.com
X-Virus-Scanned: Clear (ClamAV 0.103.6/26617/Thu Aug 4 09:54:12 2022)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <Yuup2A8vqJGL2rDD@anomaly>
X-Mailman-Original-References: <25320.3769.224412.136125@ixdm.fritz.box>
<DB6PR01MB3895BEDFCE37B51C1C470113839F9@DB6PR01MB3895.eurprd01.prod.exchangelabs.com>
 by: 2QdxY4Rz...@potatochowder.com - Thu, 4 Aug 2022 11:13 UTC

On 2022-08-04 at 09:41:00 +0200,
Albert-Jan Roskam <sjeik_appie@hotmail.com> wrote:

> Thank you both. I'll give this a try. I think it would be nice if
> the standard library function atexit.register would be improved,
> such that the registered functions would not only be called upon
> (a) normal program termination, but that one could also register
> functions that are called (b) upon error (c) unconditionally. Much
> like (a) try - (b) except - (c) finally.

There. You've just designed the top level of a better behaved, more
robust application (completely untested):

on_normal_exit_funcs = list()
on_error_exit_funcs = list()
on_any_exit_funcs = list()

def run_exit_funcs(exit_funcs):
for func in exit_funcs:
try: func()
except e: maybe_do_some_logging(e)

try:
run_the_application()
run_exit_funcs(on_normal_exit_funcs)
except:
run_exit_funcs(on_error_exit_funcs)
finally:
run_exit_funcs(on_any_exit_funcs)

def register_normal_exit_func(f):
on_normal_exit_funcs.append(f)

def register_error_exit_func(f):
on_error_exit_funcs.append(f)

def register_any_exit_func(f):
on_any_exit_funcs.append(f)

No, really. There are worse ways to build an extremely generic, fairly
minimalist application framework.

Season to taste,¹ add it to your personal (or company) toolbox, and
refine and improve it as things come up. You may discover some number
of common exit functions that are useful across appliations, too.

¹ are you object oriented, functional, imperative, or something else?
do you like long names, short names, names that follow some existing
coding standard, non-English names? do you have a standardized
logging/exception library?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor