Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Dinosaurs aren't extinct. They've just learned to hide in the trees.


devel / comp.lang.python / How best to handle SystemError in ctypes callback

SubjectAuthor
o How best to handle SystemError in ctypes callbackJarrod G

1
How best to handle SystemError in ctypes callback

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: jarro...@gmail.com (Jarrod G)
Newsgroups: comp.lang.python
Subject: How best to handle SystemError in ctypes callback
Date: Wed, 5 Jan 2022 17:26:16 -0500
Lines: 32
Message-ID: <mailman.113.1641421710.3079.python-list@python.org>
References: <CAJMuovqyCgmnLpJ06t=aFvfjaW4=A+VAyfNpyCz6KCz8Y7=0ag@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de 6M7dkLtPqPsVl7BFfPjb0gIlqLJt/7BZopoLgLd6BVxQ==
Return-Path: <jarrodkg@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=KxwfiIfB;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.077
X-Spam-Evidence: '*H*': 0.85; '*S*': 0.00; 'def': 0.04; 'approach?':
0.09; 'import': 0.15; 'subject:best': 0.16; 'to:addr:python-list':
0.20; 'input': 0.21; 'subject:How': 0.23; 'message-
id:@mail.gmail.com': 0.32; 'received:google.com': 0.34;
'following': 0.35; 'received:209.85.166': 0.35;
'from:addr:gmail.com': 0.35; 'received:209.85': 0.37; 'way': 0.38;
'received:209': 0.39; 'handle': 0.39; 'want': 0.40; 'best': 0.61;
'internal': 0.63; 'skip:r 20': 0.64; 'happens': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:from:date:message-id:subject:to;
bh=GwtFMEvZVD8SPv6Fje32vItv3ed8mcUiLwfM+65tdFQ=;
b=KxwfiIfBImimBwxt6oudlkjK7HAc0AC7CCFQFy/+Qd8iisAeQE8ACCyUrAqLF4KXa5
VqaJ5rrm0AwZmUZnl2riv9wbnjWxlL7qY+hw519GkuVzqRlLcVsB5ytKGDcosrUMIYGD
gI7mhpz9DBM8NJZf/+JcQDkAj71u4YdFnvF4RGQ7o/uKaNToJx8ysgzYrLbRznNXCSN9
srs7gH02YQhSH+yhGIuJsMvZdu6IlKUH0mUjQNH177f5r+x9GR0TBFFsUyZ5+IIlMjKG
hXT8QTFoQchVfmlS+pf8Z9t/G/VGLon2WSnNNqMwvyOP37d984UVwlJNHnGo8g3PX1TW
7uJw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
bh=GwtFMEvZVD8SPv6Fje32vItv3ed8mcUiLwfM+65tdFQ=;
b=rjv6Zpz4HBhrSrXdc9KIgSaigATeg6D95xTdevFVn4H4amRwhey/3YsKXt3CgIEMhV
iw4mzmOcShSkNGcqep1NLRsN2zZDzjEd4fIw9SCjRFnQQSRYS2D+RoDB0QYXMg2XnE99
pXlYT6hYNT5KFlVVUhYrUtYqJqK2W64hr936z3+Ej27G+DeE0JVeI1nJkqsJSBvlF4Pn
aos+KkcE1gPuwf9EXg1Qf7OSnS78WRroPTjoN+9nMK5ri0REv8PGcJYfsIqx0OnbZYUq
kyXV2XmpDocL1OqbE5FqNzIJNF7sa2GpP/k9jZNmVTd7Q9f7VgzfxS6jZJFIC9lqG6Mo
xL1A==
X-Gm-Message-State: AOAM530wW3i+ZAklumBRBJNbwb3bDd+jfFoGICpaFtjcViaiuRdDnUek
1UbM6Rg6mLQRUTmlYrUeL4xb8Z7EHgmk+wAL8MUNZ7ly9zs=
X-Google-Smtp-Source: ABdhPJygvUwKxBumjCsS8OjJjrcNpHoZGFZq4kYKGcAsgZyt7uiiVhwcvVux6byKvEy4DEhd6a2KZ6cDrtQR4sdxnRg=
X-Received: by 2002:a02:6f5b:: with SMTP id b27mr28783747jae.49.1641421586745;
Wed, 05 Jan 2022 14:26:26 -0800 (PST)
X-Mailman-Approved-At: Wed, 05 Jan 2022 17:28:29 -0500
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
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: <CAJMuovqyCgmnLpJ06t=aFvfjaW4=A+VAyfNpyCz6KCz8Y7=0ag@mail.gmail.com>
 by: Jarrod G - Wed, 5 Jan 2022 22:26 UTC

With the following code:

import ctypes
> import readline
> from ctypes.util import find_library
>
> rl = ctypes.cdll.LoadLibrary(find_library('readline'))
>
> rl_redisplay = rl.rl_redisplay
> rl_redisplay.restype = None
> rl_redisplay.argtypes = None
>
> rl_redisplay_function = ctypes.c_void_p.in_dll(rl, 'rl_redisplay_function')
>
> def _wrapper():
> rl_redisplay()
>
> fp = ctypes.CFUNCTYPE(None)(_wrapper)
> rl_redisplay_function.value = ctypes.cast(fp, ctypes.c_void_p).value
>
> input('enter ctrl-c now')
>

What is the best or correct way to handle SystemError when a Ctrl-c happens
at the input prompt? Is a try/except around rl_redisplay the best or
correct approach?

Based on the docs for SystemError (
https://docs.python.org/3/library/exceptions.html#SystemError), I don't
want to mask/hide an internal error.

Jarrod

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor