-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-31804: multiprocessing calls flush on sys.stdout at exit even if … #5492
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
Changes from 1 commit
cab49f2
fe03c62
e860a4f
5e91e60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -653,6 +653,47 @@ def test_forkserver_sigkill(self): | |
self.check_forkserver_death(signal.SIGKILL) | ||
|
||
|
||
class TestStdOutAndErr(unittest.TestCase): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps you can move these tests closer to the test added by the other PR: I also wonder if those tests can be unified. They seem to be doing very similar things. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My 1st guess was to update that test case too. But someone has disabled that test case by adding a _ prefix to the class name. Also the test module itself is prefixed by _. So these tests are not run automatically. And I couldn't make that test case work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha. You misunderstood how (and that's why those test classes have an underscore prefix) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoa! :) Now it all makes sense! I will make yet another commit (3rd) and unify the test cases. |
||
@staticmethod | ||
def closeIO(stream_name): | ||
getattr(sys, stream_name).close() | ||
|
||
@staticmethod | ||
def removeIO(stream_name): | ||
setattr(sys, stream_name, None) | ||
|
||
def test_closed_stdio(self): | ||
""" | ||
bpo-28326: multiprocessing.Process depends on sys.stdout being open | ||
""" | ||
self.run_process(self.closeIO) | ||
|
||
def test_no_stdio(self): | ||
""" | ||
bpo-31804: If you start Python by pythonw then sys.stdout and | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's no need for the docstring (or comment) to be that long. Just put the reference to the issue number + a 2- or 3-line summary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I trimmed the docstring. |
||
sys.stderr are set to None. If you also use multiprocessing | ||
then when the child process finishes BaseProcess._bootstrap | ||
calls sys.stdout.flush() and sys.stderr.flush() finally. | ||
This causes the process return code to be not zero (it is 1). | ||
|
||
This unit test sets sys.stdio and sys.stderr to None, instead of | ||
changing the Python interpreter to use when starting a child process | ||
to pythonw.exe because that is Windows specific. This method | ||
cannot test if there is an error (because of stdout or stderr is None) | ||
before the target function is called. However the errors have occurred | ||
in the multiprocessing outro so this can test the previously mentioned | ||
bug. Also this way the feature can be tested on other operating | ||
systems too. | ||
""" | ||
self.run_process(self.removeIO) | ||
|
||
def run_process(self, target): | ||
for stream_name in ('stdout', 'stderr'): | ||
proc = multiprocessing.Process(target=target, args=(stream_name,)) | ||
proc.start() | ||
proc.join() | ||
self.assertEqual(proc.exitcode, 0) | ||
|
||
# | ||
# | ||
# | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A minor issue, but I'd like to stick to the idiom already used in the previous PR: https://github.com/python/cpython/pull/4073/files#diff-d6a41af14d72f372f37ced0cc15c1f58L17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course. It's the easier to ask for forgiveness than permission idiom.