multiprocessing.sharedctypes: SynchronizedBase calls get_context(force=True), which raises TypeError

Aberta
#156,062 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
20/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
python

Direção de pesquisa

Revise Lib/multiprocessing/sharedctypes.py, especialmente SynchronizedBase.init e os caminhos de construção direta de Synchronized, SynchronizedArray e SynchronizedString. Reproduza o TypeError relatado, depois inspecione o teste de regressão mencionado na issue e verifique se a construção direta é bem-sucedida sem um lock ou context.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

stdlib topic-multiprocessing type-bug

Bug report

Bug description:

multiprocessing.sharedctypes.SynchronizedBase.__init__ calls get_context(force=True) when it is given neither a lock nor a ctx:

https://github.com/python/cpython/blob/20e6c2fc7c9fe5a8d62aa8f1b66a1bd72a24cf74/Lib/multiprocessing/sharedctypes.py#L187-L193

But get_context() has never accepted a force argument (set_start_method() does), so constructing one of the synchronized wrapper classes directly, without a lock or a context, fails:

>>> from multiprocessing.sharedctypes import RawValue, Synchronized
>>> Synchronized(RawValue('i', 7))
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    Synchronized(RawValue('i', 7))
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File ".../multiprocessing/sharedctypes.py", line 192, in __init__
    ctx = ctx or get_context(force=True)
TypeError: DefaultContext.get_context() got an unexpected keyword argument 'force'

The same applies to SynchronizedArray and SynchronizedString. The module-level helpers (Value(), Array(), synchronized()) are not affected because they always resolve a context themselves and pass it down, which is why this has gone unnoticed: the line dates from the commit that introduced contexts (b1694cf588, bpo-18999, 2013).

The fix is to call get_context() without the bogus argument, which is what synchronized() does a few lines above. Found by running pylint over the standard library (unexpected-keyword-arg). I have a PR with a regression test ready.

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

macOS

Linked PRs
  • gh-156063
Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Merge médio
1d 9h
PRs com merge (30d)
558

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de python/cpython

Todas as issues de python/cpython

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.