Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Give PyErr_CheckSignals guide-level documentation #134075

Open
Labels
docsDocumentation in the Doc dir
@zackw

Description

@zackw

Documentation

Compiled extensions that "want to be interruptible by user requests" need to callPyErr_CheckSignals periodically; when it returns-1, they should stop work, clean up after themselves, and return to the interpreter.

This function is not mentioned at all in the extending and embedding guide, and its reference documentation makes it sound unimportant. As a result, many extension authors are (it seems to me) not aware that it exists or that they ought to be calling it, and so many extensions thatshould be interruptible by user requests aren't. For example, if you execute this code

>>> import numpy as np>>> rng = np.random.default_rng()>>> x = rng.random(1000000000)

and then immediately hit control-C, you'll be waiting at least a few seconds before you get the prompt back.

PyErr_CheckSignals also has the unusual property of potentially executing arbitrary Python code before returning to its caller, which makes it easy to use unsafely. Making an extension interruptible throughout may necessitate callingPyErr_CheckSignals from innermost loops where one would ideally release the GIL, which makes that worse (see#133465).

Thus, I suggest that a guide to correct use ofPyErr_CheckSignals should be added to the extending and embedding guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp