[New-bugs-announce] [issue35477] multiprocessing.Pool.__enter__() should raise an exception if called twice

STINNER Victor report at bugs.python.org
Wed Dec 12 18:08:12 EST 2018


New submission from STINNER Victor <vstinner at redhat.com>:

On a file, "with file:" fails if it's used a second time:
---
fp = open('/etc/issue')
with fp:
    print("first")
with fp:
    print("second")
---

fails with "ValueError: I/O operation on closed file", because file.__enter__() raises this exception if the file is closed.

I propose to have the same behavior on multiprocessing.Pool.__enter__() to detect when the multiprocessing API is misused.

Anyway, after the first "with pool:" block, the pool becomes unusable to schedule now tasks: apply() raise ValueError("Pool not running") in that case for example.

----------
components: Library (Lib)
messages: 331719
nosy: vstinner
priority: normal
severity: normal
status: open
title: multiprocessing.Pool.__enter__() should raise an exception if called twice
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35477>
_______________________________________


More information about the New-bugs-announce mailing list