John-P / wsic

Whole Slide image (WSI) conversion for brightfield histology images
MIT License
33 stars 4 forks source link

Tile read timed out when converting images #52

Closed himekifee closed 1 year ago

himekifee commented 2 years ago

Description

When converting an image, the program created a crashdump and exited.

What I Did

/usr/local/bin/python /usr/local/bin/wsic convert -i /xxx.jp2 -o /xxx.tiff -rt 4096 4096 -w 30 -mpp 0.5 0.5 --no-ome --overwrite -to 180 -c jpeg -cl 90 -d 2 -d 4 -d 8

Reading:   1%|          | 10/828 [00:23<31:10,  2.29s/it] 
Writing:   0%|          | 106/204840 [00:23<12:07:59,  4.69it/s]
                                                                /usr/local/lib/python3.9/site-packages/wsic/readers.py:385: UserWarning: Failed to get next tile after 100 attempts. Dumping debug information.9,  4.69it/s]
  warnings.warn(
Reading:   1%|          | 10/828 [03:23<4:37:56, 20.39s/it]
Writing:   0%|          | 160/204840 [03:23<72:26:45,  1.27s/it]
Traceback (most recent call last):
  File "/usr/local/bin/wsic", line 8, in <module>
Reader Shape (145456, 92000, 3)
Read Tile Size (4096, 4096)
Yield Tile Size (256, 256)
    sys.exit(main())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
Read Mosaic Shape (36, 23)
Yield Mosaic Shape (569, 360)
Read Index (0, 10)
Yield Index (0, 160)
Remaining Reads (:10) [(1, 17), (1, 18), (1, 19), (1, 20), (1, 21), (1, 22), (2, 0), (2, 1), (2, 2), (2, 3)]
Enqueued {(1, 0), (1, 6), (0, 14), (1, 3), (1, 9), (0, 11), (0, 17), (1, 12), (0, 20), (1, 15), (1, 2), (0, 10), (0, 16), (1, 5), (1, 11), (0, 13), (0, 19), (1, 8), (1, 14), (0, 22), (1, 1), (1, 4), (0, 12), (1, 7), (1, 13), (0, 15), (0, 21), (1, 10), (1, 16), (0, 18)}
Reordering Dict (keys) dict_keys([(0, 22), (0, 21), (0, 18), (0, 15), (1, 1), (0, 14), (0, 11), (1, 4), (0, 13), (1, 5), (1, 3), (0, 12), (0, 17), (0, 19), (1, 0), (1, 6), (1, 8), (1, 10), (1, 7), (1, 13), (1, 14), (1, 15), (1, 12), (1, 16), (1, 9), (1, 11)])
Queue Size 0
Intermediate Read slices (slice(0, 256, None), slice(40960, 41216, None))
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/wsic/cli.py", line 223, in convert
    writer.copy_from_reader(
  File "/usr/local/lib/python3.9/site-packages/wsic/writers.py", line 593, in copy_from_reader
    tif.write(
  File "/usr/local/lib/python3.9/site-packages/tifffile/tifffile.py", line 3116, in write
    for tileindex, chunk in enumerate(
  File "/usr/local/lib/python3.9/site-packages/tifffile/tifffile.py", line 20438, in encode_tiles
    tile = next(tileiter)
  File "/usr/local/lib/python3.9/site-packages/tifffile/tifffile.py", line 21536, in newiter
    yield from iterator
  File "/usr/local/lib/python3.9/site-packages/tqdm/std.py", line 1195, in __iter__
    for obj in iterable:
  File "/usr/local/lib/python3.9/site-packages/wsic/readers.py", line 406, in __next__
    raise IOError(f"Tile read timed out at index {self.yield_index}")
OSError: Tile read timed out at index (0, 160)
Exception ignored in: <function MultiProcessTileIterator.__del__ at 0x7f3a53e61160>
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/wsic/readers.py", line 509, in __del__
    self.close()
  File "/usr/local/lib/python3.9/site-packages/wsic/readers.py", line 501, in close
    executor.map(lambda p: p.join(1), self.processes)
  File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 598, in map
    fs = [self.submit(fn, *args) for args in zip(*iterables)]
  File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 598, in <listcomp>
    fs = [self.submit(fn, *args) for args in zip(*iterables)]
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 169, in submit
    raise RuntimeError('cannot schedule new futures after '
RuntimeError: cannot schedule new futures after interpreter shutdown

There is no other I/O intensive job while running the task.

himekifee commented 2 years ago

FYI it's more reproducible when using a high worker count.

John-P commented 1 year ago

Hi @himekifee I think I may have tracked down the cause of this issue and it should be fixed by #53 and #48.

John-P commented 1 year ago

This should be fixed in version 0.7.0 hopefully. Publishing to PyPI now.