-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multiprocessing.Queue raises AssertionError #67061
Comments
putting something in Queue(multiprocessing.Queue) after closing it raises an AssertionError. To Reproduce: >>> from multiprocessing import Queue
>>> q = Queue()
>>> q.close()
>>> q.put("ok")
Traceback (most recent call last):
...
AssertionError
>>> from multiprocessing import Queue
>>> q = Queue()
>>> q.close()
>>> q.get()
Traceback (most recent call last):
...
OSError: handle is closed |
Here is the trivial patch for that :) |
The proposed patch would potentially break existing code which anticipates the current behavior. The potential negative impact means this particular proposed patch is not viable. Choices forward include: (1) better documenting the existing, established implementation behavior (perhaps having the assert provide a more informative message), or (2) altering the behavior in a new release version (perhaps 3.6 when it comes) and documenting that change appropriately there. As to what sort of exception we should expect in this situation, unfortunately comparing to the queue module's Queue does not help guide expectations much since it does not have need of a close(). Of the two above options, I'm more inclined towards the first. Does @Joseph.Siddall have other motivations that helped motivate this suggested improvement? |
See bpo-5001 for more general cleanup in multiprocessing.
+1. We can also document AssertionError in older Python versions. |
The expected behaviour here would be to raise ValueError, as on other closed objects: >>> s = io.StringIO()
>>> s.close()
>>> s.write("")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file |
I don't think we need to document AssertionError in older Python versions. This is an implementation detail. We don't document all exceptions that can be raised with improper use of the API. Just don't do this. In addition, using the assert statement for validating user input or the object state which depends on user actions is a bad style. We shouldn't encourage this by documenting it as a behavior of the stdlib. It was a bug, and it is fixed now. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: