Skip to content

Thread-safe atomic countersΒ #124366

@colesbury

Description

@colesbury

Feature or enhancement

Python doesn't currently have a thread-safe atomic counter. CPython currently internally uses a few different patterns to implement thread-safe counters. For example, some test code uses appends to a shared list because the implementation of list.append() is atomic.

We should provide a counter that is explicitly thread-safe so that people don't have to rely on other idioms. The minimum initial API should provide:

  • atomic increment
  • get value (i.e., inspect)

The threading module may be a good place for it.

cc @rhettinger

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions