Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PyEval_ReInitThreads() from the public C API #80909

Closed
vstinner opened this issue Apr 25, 2019 · 6 comments
Closed

Remove PyEval_ReInitThreads() from the public C API #80909

vstinner opened this issue Apr 25, 2019 · 6 comments
Labels
3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@vstinner
Copy link
Member

BPO 36728
Nosy @gpshead, @vstinner
PRs
  • bpo-36728: Remove PyEval_ReInitThreads() from C API #13241
  • bpo-36728: Remove PyEval_ReInitThreads documentation #13282
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-05-13.10:35:55.872>
    created_at = <Date 2019-04-25.23:22:09.307>
    labels = ['interpreter-core', '3.8']
    title = 'Remove PyEval_ReInitThreads() from the public C API'
    updated_at = <Date 2019-05-13.14:22:56.780>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2019-05-13.14:22:56.780>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-13.10:35:55.872>
    closer = 'vstinner'
    components = ['Interpreter Core']
    creation = <Date 2019-04-25.23:22:09.307>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36728
    keywords = ['patch']
    message_count = 6.0
    messages = ['340868', '342147', '342279', '342291', '342306', '342333']
    nosy_count = 2.0
    nosy_names = ['gregory.p.smith', 'vstinner']
    pr_nums = ['13241', '13282']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue36728'
    versions = ['Python 3.8']

    @vstinner
    Copy link
    Member Author

    PyEval_ReInitThreads() is used internally by PyOS_AfterFork_Child(). I don't see the point of calling it directly. If you care of threads after fork, just call PyOS_AfterFork_Child(), no?

    I propose to remove PyEval_ReInitThreads() from the public C API.

    Problem: it's documented as a public function in High-level API of the Python Initialization API:
    https://docs.python.org/dev/c-api/init.html#c.PyEval_ReInitThreads

    On the Internet, I found a single project calling directly this function, but it's only in a test used to the test Python threading API:
    https://github.com/DataDog/go-python3/blob/master/thread_test.go

    func TestThreadInitialization(t *testing.T) {
    Py_Initialize()
    PyEval_InitThreads()

    	assert.True(t, PyEval_ThreadsInitialized())
    
    	PyEval_ReInitThreads()
    }

    I don't think that the PyEval_ReInitThreads() call here makes any sense.

    @vstinner vstinner added 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Apr 25, 2019
    @vstinner
    Copy link
    Member Author

    The function was added 19 years ago:

    commit fee3a2d
    Author: Guido van Rossum <guido@python.org>
    Date: Sun Aug 27 17:34:07 2000 +0000

    Charles Waldman's patch to reinitialize the interpreter lock after a
    fork.  This solves the test_fork1 problem.  (ceval.c, signalmodule.c,
    intrcheck.c)
    
    SourceForge: [ Patch bpo-101226 ] make threading fork-safe
    

    @gpshead
    Copy link
    Member

    gpshead commented May 13, 2019

    fwiw - i agree that this can be removed. it has no reason to ever be called directly. i double checked in our massive internal codebase at work and found no calls other than python interpreters themselves.

    @vstinner
    Copy link
    Member Author

    i double checked in our massive internal codebase at work and found no calls other than python interpreters themselves.

    Thanks. It confirms what I understood using GitHub code search (see my initial message).

    @vstinner
    Copy link
    Member Author

    New changeset d5d9e81 by Victor Stinner in branch 'master':
    bpo-36728: Remove PyEval_ReInitThreads() from C API (GH-13241)
    d5d9e81

    @vstinner
    Copy link
    Member Author

    New changeset c1f7262 by Victor Stinner in branch 'master':
    bpo-36728: Remove PyEval_ReInitThreads documentation (GH-13282)
    c1f7262

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants