python / python/cpython

Improve `__repr__` string of synchronize tools in the `multiprocessing` module.

Aperta
#155,092 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdlib topic-multiprocessing type-feature
Lingua principale
Python
Stelle
77.2k
Fork
36k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Feature or enhancement

Proposal:

To be consistant with representation string of threading sychronize tools and in accordance with the discussion from the #149447 PR , the missing id information must be added in the __repr__ of the following synchronization classes:

  • Lock, Rlock,
  • Semaphore, BoundedSemaphore,
  • Condition.

and refactoring must be performed to these 2 classes:

  • Event,
  • Barrier.

See some examples below:

import threading
import multiprocessing

print(threading.Semaphore(3))
print(multiprocessing.Semaphore(3))

print(threading.Lock())
print(multiprocessing.Lock())

print(threading.Event())
print(multiprocessing.Event())

print(threading.Barrier(2))
print(multiprocessing.Barrier(2))

The ouput is:

<threading.Semaphore at 0x10378c8a0: value=3>
<Semaphore(value=3)>
<unlocked _thread.lock object at 0x103612040>
<Lock(owner=None)>
<threading.Event at 0x10378ccc0: unset>
<Event at 0x10378ccc0 unset>
<threading.Barrier at 0x10378ccc0: waiters=0/2>
<multiprocessing.synchronize.Barrier at 0x10378ccc0: waiters=0/2>

A PR will be published soon.

cc @gpshead

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

#149447

Linked PRs
  • gh-155593

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia nel modulo multiprocessing con le classi Lock, Rlock, Semaphore, BoundedSemaphore, Condition, Event e Barrier, confrontando le loro rappresentazioni con threading e con la discussione in #149447. Il lavoro è completo quando le informazioni sull’ID richieste sono incluse per gli strumenti di sincronizzazione elencati ed Event e Barrier ricevono il refactoring proposto; nota che PR #155593 è già collegato nell’issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
operating-systems
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.