-
Notifications
You must be signed in to change notification settings - Fork 5
Description
PySE master cannot be used over multiple threads.
I feel like this is a recent development since I was able to run pyse in multiple threads before (in v0.4.0 to be exact). Note that in the following example already has allow_multiprocessing set to False. This is to avoid confusion as to where the threading problem comes from but also to avoid the issue described here: #158
import threading
from sourcefinder.accessors import open as pyse_open
from sourcefinder.accessors import sourcefinder_image_from_accessor
from sourcefinder.config import Conf
def process_image():
path = "test/data/GRB201006A_final_2min_srcs-t0002-image-pb_cutout.fits"
im = pyse_open(path)
pyse_im = sourcefinder_image_from_accessor(im, conf=Conf({"allow_multiprocessing":False},{}))
results = pyse_im.extract(det=5,anl=5)
if __name__ == "__main__":
thread_1 = threading.Thread(target=process_image)
thread_2 = threading.Thread(target=process_image)
thread_1.start()
thread_2.start()
thread_1.join()
thread_2.join()When I run this I get the following error:
Numba workqueue threading layer is terminating: Concurrent access has been detected.
- The workqueue threading layer is not threadsafe and may not be accessed concurrently by multiple threads. Concurrent access typically occurs through a nested parallel region launch or by calling Numba parallel=True functions from multiple Python threads.
- Try using the TBB threading layer as an alternative, as it is, itself, threadsafe. Docs: https://numba.readthedocs.io/en/stable/user/threading-layer.html
If you read the docs that the error points to it will tell you to use another package that can be used as a threadsafe runtime like tbb or openmp. While this works, I would prefer not to add an extra multithreaded runtime on top of the one I am already running. Besides, I was able to get it to run on my laptop but not on my desktop with errors like "ValueError: No threading layer could be loaded.", which occurs because I apparently have some outdated software installed unrelated to pip. I am not eager to dive into this conflict since I would prefer not to have tbb or openmp in the first place.
I can get it to run if I set all target="parallel" to target="cpu". That way numba does not try to spin up a multithreaded runtime. I understand we want to keep the parallel option as a default for people who use PySE from the command line, but can we maybe add the option to run with target set to 'cpu'?
Cheers,
Timo
P.S.
If you want to replicate the example in version v0.4.0 you need to use results = pyse_im.extract(5,5) since it does not yet use the config object for all parameters. When that runs I do however get the warning:
/media/timo/samsung_870_evo/software/astron/pyse/venv/lib/python3.11/site-packages/numba/np/ufunc/parallel.py:371: NumbaWarning: The TBB threading layer requires TBB version 2021 update 6 or later i.e., TBB_INTERFACE_VERSION >= 12060. Found TBB_INTERFACE_VERSION = 12050. The TBB threading layer is disabled.