-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
[2.7] bpo-31530: Stop crashes when iterating over a file on multiple threads. #3672
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 all commits
d175527
bc2b365
0f871d7
8a0e1ee
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 |
---|---|---|
|
@@ -652,6 +652,38 @@ def io_func(): | |
self.f.writelines('') | ||
self._test_close_open_io(io_func) | ||
|
||
def test_iteration_torture(self): | ||
# bpo-31530: Crash when concurrently iterate over a file. | ||
with open(self.filename, "wb") as fp: | ||
for i in xrange(2**20): | ||
fp.write(b"0"*50 + b"\n") | ||
with open(self.filename, "rb") as f: | ||
def iterate(): | ||
try: | ||
for l in f: | ||
pass | ||
except IOError: | ||
pass | ||
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. It's probably a better stress test to continue looping even when you get an exception. 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. This makes the test tooooooo slow. I have killed it after 8 minutes. 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. Decrease the size of the file then? 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.
|
||
self._run_workers(iterate, 10) | ||
|
||
def test_iteration_seek(self): | ||
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. Please add a comment with a least "bpo-31530". 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. done |
||
# bpo-31530: Crash when concurrently seek and iterate over a file. | ||
with open(self.filename, "wb") as fp: | ||
for i in xrange(10000): | ||
fp.write(b"0"*50 + b"\n") | ||
with open(self.filename, "rb") as f: | ||
it = iter([1] + [0]*10) # one thread reads, others seek | ||
def iterate(): | ||
try: | ||
if next(it): | ||
for l in f: | ||
pass | ||
else: | ||
for i in range(100): | ||
f.seek(i*100, 0) | ||
except IOError: | ||
pass | ||
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. similarly here |
||
self._run_workers(iterate, 10) | ||
|
||
@unittest.skipUnless(os.name == 'posix', 'test requires a posix system.') | ||
class TestFileSignalEINTR(unittest.TestCase): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Fixed crashes when iterating over a file on multiple threads. | ||
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 suggest to complete the description: seek() and next() methods of file objects now raise an exception during concurrent operation on the same file object. A lock can be used to prevent the error. 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. done |
||
seek() and next() methods of file objects now raise an exception during | ||
concurrent operation on the same file object. | ||
A lock can be used to prevent the error. |
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.
Please add a comment with a least "bpo-31530".
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.
done