Skip to content

Commit ae36c14

Browse files
martaiborraFrancescAlted
authored andcommitted
Check multithreading only for python plugin functions
1 parent dd3e197 commit ae36c14

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

blosc2/blosc2_ext.pyx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -646,24 +646,34 @@ def get_blocksize():
646646

647647
cdef _check_cparams(blosc2_cparams *cparams):
648648
if cparams.nthreads > 1:
649-
if BLOSC2_USER_REGISTERED_CODECS_START <= cparams.compcode <= BLOSC2_USER_REGISTERED_CODECS_STOP:
650-
raise ValueError("Cannot use multi-threading with user defined codecs")
651-
elif any([BLOSC2_USER_REGISTERED_FILTERS_START <= filter <= BLOSC2_USER_REGISTERED_FILTERS_STOP
652-
for filter in cparams.filters]):
653-
raise ValueError("Cannot use multi-threading with user defined filters")
654-
elif cparams.prefilter != NULL:
649+
if BLOSC2_USER_REGISTERED_CODECS_START <= cparams.compcode <= BLOSC2_USER_REGISTERED_CODECS_STOP\
650+
and cparams.compcode in blosc2.ucodecs_registry.keys():
651+
raise ValueError("Cannot use multi-threading with user defined Python codecs")
652+
653+
ufilters = [BLOSC2_USER_REGISTERED_FILTERS_START <= filter <= BLOSC2_USER_REGISTERED_FILTERS_STOP
654+
for filter in cparams.filters]
655+
for i in range(len(ufilters)):
656+
if ufilters[i] and cparams.filters[i] in blosc2.ufilters_registry.keys():
657+
raise ValueError("Cannot use multi-threading with user defined Python filters")
658+
659+
if cparams.prefilter != NULL:
655660
raise ValueError("`nthreads` must be 1 when a prefilter is set")
656661

657662
cdef _check_dparams(blosc2_dparams* dparams, blosc2_cparams* cparams=NULL):
658663
if cparams == NULL:
659664
return
660665
if dparams.nthreads > 1:
661-
if BLOSC2_USER_REGISTERED_CODECS_START <= cparams.compcode <= BLOSC2_USER_REGISTERED_CODECS_STOP:
662-
raise ValueError("Cannot use multi-threading with user defined codecs")
663-
elif any([BLOSC2_USER_REGISTERED_FILTERS_START <= filter <= BLOSC2_USER_REGISTERED_FILTERS_STOP
664-
for filter in cparams.filters]):
665-
raise ValueError("Cannot use multi-threading with user defined filters")
666-
elif dparams.postfilter != NULL:
666+
if BLOSC2_USER_REGISTERED_CODECS_START <= cparams.compcode <= BLOSC2_USER_REGISTERED_CODECS_STOP\
667+
and cparams.compcode in blosc2.ucodecs_registry.keys():
668+
raise ValueError("Cannot use multi-threading with user defined Python codecs")
669+
670+
ufilters = [BLOSC2_USER_REGISTERED_FILTERS_START <= filter <= BLOSC2_USER_REGISTERED_FILTERS_STOP
671+
for filter in cparams.filters]
672+
for i in range(len(ufilters)):
673+
if ufilters[i] and cparams.filters[i] in blosc2.ufilters_registry.keys():
674+
raise ValueError("Cannot use multi-threading with user defined Python filters")
675+
676+
if dparams.postfilter != NULL:
667677
raise ValueError("`nthreads` must be 1 when a postfilter is set")
668678

669679

0 commit comments

Comments
 (0)