Skip to content

threading._get_ident(): remove it in the doc or make it public #56237

Closed

Description

@vstinner
BPO 12028
Nosy @brettcannon, @birkenfeld, @rhettinger, @pitrou, @vstinner, @merwok
Files
  • threading_get_ident.patch
  • 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 2011-05-30.21:04:22.473>
    created_at = <Date 2011-05-07.10:24:44.959>
    labels = ['library', 'docs']
    title = 'threading._get_ident(): remove it in the doc or make it public'
    updated_at = <Date 2011-05-30.21:23:58.809>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2011-05-30.21:23:58.809>
    actor = 'python-dev'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2011-05-30.21:04:22.473>
    closer = 'python-dev'
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2011-05-07.10:24:44.959>
    creator = 'vstinner'
    dependencies = []
    files = ['22089']
    hgrepos = []
    issue_num = 12028
    keywords = ['patch']
    message_count = 10.0
    messages = ['135441', '135443', '136086', '136088', '136089', '136092', '136647', '136731', '137328', '137333']
    nosy_count = 8.0
    nosy_names = ['brett.cannon', 'georg.brandl', 'rhettinger', 'pitrou', 'vstinner', 'eric.araujo', 'docs@python', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue12028'
    versions = ['Python 3.3']

    Activity

    1. vstinner commented on May 7, 2011

      @vstinner
      MemberAuthor

      I don't know why threading._get_ident() (which is _thread.get_ident()) is private: this function is safe.

      This function becomes useful with pthread_kill() which will be added by bpo-8407.

    2. added
      docsDocumentation in the Doc dir
      stdlibStandard Library Python modules in the Lib/ directory
      on May 7, 2011
    3. vstinner commented on May 7, 2011

      @vstinner
      MemberAuthor

      I think that threading._get_ident() is more reliable than threading.current_thread().ident because Thread.ident can be None in some cases.

    4. vstinner commented on May 16, 2011

      @vstinner
      MemberAuthor

      @pitrou: What do you think Antoine?

    5. vstinner commented on May 16, 2011

      @vstinner
      MemberAuthor

      The threading API changed in Python 3 with the PEP-3108, especially and issue bpo-2875. Extract of the PEP:

      "thread [done]

      • People should use 'threading' instead.
        • Rename 'thread' to _thread.
        • Deprecate dummy_thread and rename _dummy_thread.
        • Move thread.get_ident over to threading.
      • Guido has previously supported the deprecation [13]."

      The issue was closed by the commit [7fe3a8648ce2], "Issue bpo-2875: Rename thread to _thread and dummy_thread to _dummy_thread."

    6. pitrou commented on May 16, 2011

      @pitrou
      Member

      I think that threading._get_ident() is more reliable than
      threading.current_thread().ident because Thread.ident can be None in
      some cases.

      In which case can it be None?

    7. vstinner commented on May 16, 2011

      @vstinner
      MemberAuthor

      In which case can it be None?

      Oh, I misunderstood threading.py. current_thread().ident cannot be None.

      During the bootstrap of a thread, Thread._ident is None, but current_thread().ident is not None because current_thread() creates a dummy thread object having the right identifer. This dummy object is destroyed at soon as the Thread object is started (see Thread._bootstrap_inner).

      current_thread().ident is a little bit "suboptimal" because it gets the identifier of the thread, it reads the corresponding thread object, and then it gets the identifier of the thread object.

      def current_thread():
          ...
          return _active[_get_ident()]
          ...
    8. merwok commented on May 23, 2011

      @merwok
      Member

      I find it strange that you propose to make a function public and remove its doc :) Is a negative missing in the bug title?

    9. changed the title [-]threading._get_ident(): remove it in the doc and make it public[/-] [+]threading._get_ident(): remove it in the doc or make it public[/+] on May 23, 2011
    10. vstinner commented on May 24, 2011

      @vstinner
      MemberAuthor

      threading_get_ident.patch: make get_ident() public, replace threading._get_ident() by threading.get_ident().

      According to this patch, get_ident() function *is* used: it is used by the logging and reprlib modules (and many tests). My patch avoids the usage of the low-level module, _thread_, in logging and reprlib.

      I adapted signal.pthread_kill() documentation to replace threading.current_thread().ident by threading.get_ident().

    11. python-dev commented on May 30, 2011

      python-devmannequin
      Mannequin

      New changeset 5548197d1f22 by Victor Stinner in branch 'default':
      Close bpo-12028: Make threading._get_ident() public, rename it to
      http://hg.python.org/cpython/rev/5548197d1f22

    12. python-dev commented on May 30, 2011

      python-devmannequin
      Mannequin

      New changeset 6387aa6b496d by Victor Stinner in branch 'default':
      Issue bpo-12028: fix NEWS entry
      http://hg.python.org/cpython/rev/6387aa6b496d

    13. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      docsDocumentation in the Doc dirstdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions