anibali / pyisyntax

A Python library for working with iSyntax file format images
MIT License
2 stars 2 forks source link

Segmentation fault when using with ThreadPoolExecutor #4

Open erikogabrielsson opened 7 months ago

erikogabrielsson commented 7 months ago

Hi,

I can read tiles using pyisyntax like this:

from isyntax import ISyntax

with ISyntax.open(slide) as wsi:
    wsi.read_tile(20, 20, 0)

However when trying to do the same withing a ThreadPoolExecutor I get Segmentation fault.

from isyntax import ISyntax
from concurrent.futures import ThreadPoolExecutor
from typing import Tuple

with ISyntax.open(slide) as wsi:
    def read_tile(tile: Tuple[int, int, int]):
        return wsi.read_tile(tile[0], tile[1], tile[2])
    tiles = [
        (20, 20, 0),
        (21, 20, 0)
    ]
    with ThreadPoolExecutor(max_workers=2) as pool:
        results = pool.map(read_tile, tiles)
    for result in results:
        print(len(result))

(running with -X faulthandler):

Fatal Python error: Segmentation fault

Current thread 0x00007fa7e3200640 (most recent call first):
  File "/mnt/c/work/external/pyisyntax/isyntax/lowlevel/libisyntax.py", line 188 in tile_read
  File "/mnt/c/work/external/pyisyntax/isyntax/wrapper.py", line 138 in read_tile
  File "/home/er-gac/work/isyntax_test.py", line 15 in read_tile
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58 in run
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 83 in _worker
  File "/usr/lib/python3.10/threading.py", line 953 in run
  File "/usr/lib/python3.10/threading.py", line 1016 in _bootstrap_inner
  File "/usr/lib/python3.10/threading.py", line 973 in _bootstrap

Thread 0x00007fa7e3a01640 (most recent call first):
  File "/mnt/c/work/external/pyisyntax/isyntax/lowlevel/libisyntax.py", line 188 in tile_read
  File "/mnt/c/work/external/pyisyntax/isyntax/wrapper.py", line 138 in read_tile
  File "/home/er-gac/work/isyntax_test.py", line 15 in read_tile
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58 in run
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 83 in _worker
  File "/usr/lib/python3.10/threading.py", line 953 in run
  File "/usr/lib/python3.10/threading.py", line 1016 in _bootstrap_inner
  File "/usr/lib/python3.10/threading.py", line 973 in _bootstrap

Thread 0x00007fa80d2f6000 (most recent call first):
  File "/usr/lib/python3.10/threading.py", line 320 in wait
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 453 in result
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 319 in _result_or_cancel
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 621 in result_iterator
  File "/home/er-gac/work/isyntax_test.py", line 21 in <module>

Extension modules: numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, _cffi_backend (total: 14)
Segmentation fault

Not sure if this is a fault in pyisyntax, as I got the same problem when trying to make my own wrapper.

anibali commented 7 months ago

Correct me if I'm wrong, but I don't think that the authors of libisyntax make any claims of thread safety. Unfortunately there is not much I am able to do if that is indeed the case.