|
13 | 13 | from io import BytesIO, StringIO
|
14 | 14 | from datetime import datetime
|
15 | 15 | import locale
|
16 |
| -from multiprocessing import Process |
| 16 | +from multiprocessing import Process, Value |
| 17 | +from ctypes import c_bool |
17 | 18 |
|
18 | 19 | import numpy as np
|
19 | 20 | import numpy.ma as ma
|
@@ -574,16 +575,29 @@ def test_unicode_and_bytes_fmt(self, fmt, iotype):
|
574 | 575 | @pytest.mark.slow
|
575 | 576 | @requires_memory(free_bytes=7e9)
|
576 | 577 | def test_large_zip(self):
|
577 |
| - def check_large_zip(): |
578 |
| - # The test takes at least 6GB of memory, writes a file larger than 4GB |
579 |
| - test_data = np.asarray([np.random.rand(np.random.randint(50,100),4) |
580 |
| - for i in range(800000)], dtype=object) |
581 |
| - with tempdir() as tmpdir: |
582 |
| - np.savez(os.path.join(tmpdir, 'test.npz'), test_data=test_data) |
| 578 | + def check_large_zip(memoryerror_raised): |
| 579 | + memoryerror_raised.value = False |
| 580 | + try: |
| 581 | + # The test takes at least 6GB of memory, writes a file larger |
| 582 | + # than 4GB |
| 583 | + test_data = np.asarray([np.random.rand( |
| 584 | + np.random.randint(50,100),4) |
| 585 | + for i in range(800000)], dtype=object) |
| 586 | + with tempdir() as tmpdir: |
| 587 | + np.savez(os.path.join(tmpdir, 'test.npz'), |
| 588 | + test_data=test_data) |
| 589 | + except MemoryError: |
| 590 | + memoryerror_raised.value = True |
| 591 | + raise |
583 | 592 | # run in a subprocess to ensure memory is released on PyPy, see gh-15775
|
584 |
| - p = Process(target=check_large_zip) |
| 593 | + # Use an object in shared memory to re-raise the MemoryError exception |
| 594 | + # in our process if needed, see gh-16889 |
| 595 | + memoryerror_raised = Value(c_bool) |
| 596 | + p = Process(target=check_large_zip, args=(memoryerror_raised,)) |
585 | 597 | p.start()
|
586 | 598 | p.join()
|
| 599 | + if memoryerror_raised.value: |
| 600 | + raise MemoryError("Child process raised a MemoryError exception") |
587 | 601 | assert p.exitcode == 0
|
588 | 602 |
|
589 | 603 | class LoadTxtBase:
|
|
0 commit comments