`python -m asyncio ps` and `python -m asyncio pstree` fail for task names that are str subclasses

Aperta
#161,952 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c, python
Ambito
devtools

Direzione di ricerca

The failure comes from read_py_str() in the remote debugger, which rejects non-compact Unicode objects, so start there and see how it reads the string layout. Run the repro with a str subclass task name, then check that python -m asyncio ps and pstree both list the task. Done means both commands succeed on that case and the existing asyncio debugging tests still pass.

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

Descrizione

type-bug
Bug report

The remote debugger cannot read the non-compact string layout used by str subclasses, so a valid task name can break both ps and pstree

Repro:

import asyncio
import os

class TaskName(str):
    def __str__(self):
        return self

async def main():
    asyncio.current_task().set_name(TaskName("worker"))
    print(os.getpid())
    await asyncio.Event().wait()

asyncio.run(main())

Run:

sudo ./python.exe -m asyncio ps <PID> --retries 0
sudo ./python.exe -m asyncio pstree <PID> --retries 0

Output:

Error retrieving tasks: Cannot read non-compact Unicode object at 0x101c625d0

asyncio docs say:

      The *value* argument can be any object, which is then
      converted to a string.

Proposed fix: add support for non-compact strings in read_py_str()

I'll work on this

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Lingua principale
Python
Stelle
78.2k
Fork
36.6k
Merge medio
19h 57m
PR unite (30g)
630

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

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.

Altre issue di python/cpython

Tutte le issue di python/cpython

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.