Skip to content

Add time.thread_time() #76206

Closed
Closed

Description

@pitrou
BPO 32025
Nosy @abalkin, @pitrou, @vstinner, @koobs
PRs
  • bpo-32025: Add time.thread_time() #4410
  • 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 2017-11-20.17:21:29.014>
    created_at = <Date 2017-11-14.13:50:20.131>
    labels = ['type-feature', '3.7']
    title = 'Add time.thread_time()'
    updated_at = <Date 2017-11-20.17:21:29.004>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2017-11-20.17:21:29.004>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-11-20.17:21:29.014>
    closer = 'vstinner'
    components = ['FreeBSD']
    creation = <Date 2017-11-14.13:50:20.131>
    creator = 'pitrou'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32025
    keywords = ['patch']
    message_count = 9.0
    messages = ['306210', '306247', '306249', '306265', '306308', '306309', '306313', '306398', '306570']
    nosy_count = 4.0
    nosy_names = ['belopolsky', 'pitrou', 'vstinner', 'koobs']
    pr_nums = ['4410']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue32025'
    versions = ['Python 3.7']

    Activity

    1. pitrou commented on Nov 14, 2017

      @pitrou
      MemberAuthor

      Currently, the time module has time.process_time(), a cross-platform function for getting per-process elapsed CPU time.

      Similarly, we could expose time.thread_time(), to get per-thread elapsed CPU time.
      On a modern POSIX platform, it can use clock_gettime(CLOCK_THREAD_CPUTIME_ID).
      On Windows, it can use GetThreadTimes(): https://msdn.microsoft.com/en-us/library/ms683237%28VS.85%29.aspx
      On other platforms, it can simply raise NotImplementedError.

      Currently, you would need ctypes hacks to call GetThreadTimes(), which is not very nice.

    2. added
      stdlib
      3.7 (EOL)
      type-feature
      on Nov 14, 2017
    3. vstinner commented on Nov 15, 2017

      @vstinner
      Member

      On other platforms, it can simply raise NotImplementedError.

      Would it be possible to not provide the function if it's not supported by a platform?

      Do you know platforms which don't support time.thread_time()?

      Do you want to add time.thread_time_ns() with nanosecond resolution (PEP-564) ? I suggest to add it to be consistent with time.process_time().

    4. vstinner commented on Nov 15, 2017

      @vstinner
      Member

      It seems like macOS doesn't implement CLOCK_THREAD_CPUTIME_ID but provides thread_info() which can be used by suming user and system times.

    5. pitrou commented on Nov 15, 2017

      @pitrou
      MemberAuthor

      Le 15/11/2017 à 02:48, STINNER Victor a écrit :

      Would it be possible to not provide the function if it's not supported by a platform?

      Probably, yes.

      Do you know platforms which don't support time.thread_time()?

      Any POSIX platform which doesn't have CLOCK_THREAD_CPUTIME_ID? It's an
      optional feature in the POSIX spec.

      Do you want to add time.thread_time_ns() with nanosecond resolution (PEP-564) ?

      Yes, I think so.

      It seems like macOS doesn't implement CLOCK_THREAD_CPUTIME_ID but
      provides thread_info() which can be used by suming user and system times.

      I don't have a macOS machine to test on, though :-)

    6. vstinner commented on Nov 15, 2017

      @vstinner
      Member

      I can work on the macOS implementation, once your PR will be merged.

    7. pitrou commented on Nov 15, 2017

      @pitrou
      MemberAuthor

      Le 15/11/2017 à 22:06, STINNER Victor a écrit :

      I can work on the macOS implementation, once your PR will be merged.

      Great!

    8. pitrou commented on Nov 15, 2017

      @pitrou
      MemberAuthor

      New changeset 4bd41c9 by Antoine Pitrou in branch 'master':
      bpo-32025: Add time.thread_time() (bpo-4410)
      4bd41c9

    9. pitrou commented on Nov 16, 2017

      @pitrou
      MemberAuthor

      Should I leave this open for you to work on the macOS implementation, Victor?

    10. vstinner commented on Nov 20, 2017

      @vstinner
      Member

      I opened bpo-32093 for macOS. I close this one.

      Nice enhancement, I already like this new clock ;-)

    11. removed
      stdlib
      on Nov 20, 2017
    12. 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

      3.7 (EOL)type-feature

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions