`OSError` when creating a `multiprocessing.Queue` with `maxsize > 32767`
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Bug report
Bug description:
While exploring multiprocessing.Queue, I encountered an exception which was confusing and I couldn't reconcile from Googling. Briefly, it seems that the Queue object allows providing a maxsize which exceeds from .synchronize import SEM_VALUE_MAX. If that occurs, the exception below is raised.
I suspect but haven't confirmed that this issue exists in main as the maxsize does not carry an upper bound.
If this is acknowledged as a bug, or at least a source of improvement for the user experience, I would be happy to provide a pull request that (1) sets an upper bound as SEM_VALUE_MAX and (2) provides a Warning that the upper bound was exceeded.
$ cat queue-test.py
import multiprocessing as mp
import sys
class mw:
def __init__(self, q):
self.q = q
def writer(self):
for i in range(5):
self.q.put(i)
print(f"writer placed {i}", flush=True)
self.q.put(None)
def reader(self):
while True:
i = self.q.get()
if i is None:
break
print(f"reader got {i}", flush=True)
if __name__ == '__main__':
maxsize = int(sys.argv[1])
ctx = mp.get_context('spawn')
qq = ctx.Queue(maxsize)
f = mw(qq)
wp = ctx.Process(target=f.writer)
wp.start()
rp = ctx.Process(target=f.reader)
rp.start()
wp.join()
rp.join()
$ python queue-test.py 32767
writer placed 0
writer placed 1
writer placed 2
writer placed 3
writer placed 4
reader got 0
reader got 1
reader got 2
reader got 3
reader got 4
$ python queue-test.py 32768
Traceback (most recent call last):
File "/Users/dtmcdonald/queue-test.py", line 24, in <module>
qq = ctx.Queue(maxsize)
^^^^^^^^^^^^^^^^^^
File "/Users/dtmcdonald/miniconda3/envs/duckdb/lib/python3.11/multiprocessing/context.py", line 103, in Queue
return Queue(maxsize, ctx=self.get_context())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dtmcdonald/miniconda3/envs/duckdb/lib/python3.11/multiprocessing/queues.py", line 49, in __init__
self._sem = ctx.BoundedSemaphore(maxsize)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dtmcdonald/miniconda3/envs/duckdb/lib/python3.11/multiprocessing/context.py", line 88, in BoundedSemaphore
return BoundedSemaphore(value, ctx=self.get_context())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dtmcdonald/miniconda3/envs/duckdb/lib/python3.11/multiprocessing/synchronize.py", line 152, in __init__
SemLock.__init__(self, SEMAPHORE, value, value, ctx=ctx)
File "/Users/dtmcdonald/miniconda3/envs/duckdb/lib/python3.11/multiprocessing/synchronize.py", line 57, in __init__
sl = self._semlock = _multiprocessing.SemLock(
^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument
$ python -c "from multiprocessing.synchronize import SEM_VALUE_MAX; print(SEM_VALUE_MAX)"
32767
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
macOS
Linked PRs
- gh-119542
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pelo gh-119542 vinculado e, em seguida, inspecione Lib/multiprocessing/queues.py e Lib/multiprocessing/synchronize.py em torno da inicialização de Queue e de SEM_VALUE_MAX. Reproduza o comportamento com queue-test.py usando os valores de maxsize 32767 e 32768; done deve tratar a falha de argumento inválido para valores acima do limite de semaphore compatível.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- operating-systems
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 25/100