@@ -39,6 +39,7 @@ from libcpp.pair cimport pair
3939from libcpp .vector cimport vector
4040from cython .operator cimport preincrement as inc , dereference as deref
4141from cpython .version cimport PY_MAJOR_VERSION
42+ from cysignals .signals cimport sig_on , sig_off
4243
4344
4445_LOGGER = logging .getLogger ("tesserocr" )
@@ -2073,8 +2074,11 @@ cdef class PyTessBaseAPI:
20732074 blockids_addr = NULL
20742075 if not paraids :
20752076 paraids_addr = NULL
2076- boxa = self ._baseapi .GetComponentImages (level , text_only , raw_image , raw_padding ,
2077- & pixa , blockids_addr , paraids_addr )
2077+ with nogil :
2078+ sig_on ()
2079+ boxa = self ._baseapi .GetComponentImages (level , text_only , raw_image , raw_padding ,
2080+ & pixa , blockids_addr , paraids_addr )
2081+ sig_off ()
20782082 if boxa == NULL :
20792083 # no components found
20802084 return []
@@ -2122,7 +2126,9 @@ cdef class PyTessBaseAPI:
21222126 """
21232127 cdef PageIterator * piter
21242128 with nogil :
2129+ sig_on ()
21252130 piter = self ._baseapi .AnalyseLayout (merge_similar_words )
2131+ sig_off ()
21262132 if piter == NULL :
21272133 return None
21282134 return PyPageIterator .createPageIterator (piter )
@@ -2145,13 +2151,15 @@ cdef class PyTessBaseAPI:
21452151 ETEXT_DESC monitor
21462152 int res
21472153 with nogil :
2154+ sig_on ()
21482155 if timeout > 0 :
21492156 monitor .cancel = NULL
21502157 monitor .cancel_this = NULL
21512158 monitor .set_deadline_msecs (timeout )
21522159 res = self ._baseapi .Recognize (& monitor )
21532160 else :
21542161 res = self ._baseapi .Recognize (NULL )
2162+ sig_off ()
21552163 return res == 0
21562164
21572165 """Methods to retrieve information after :meth:`SetImage`,
@@ -2164,13 +2172,15 @@ cdef class PyTessBaseAPI:
21642172 ETEXT_DESC monitor
21652173 int res
21662174 with nogil :
2175+ sig_on ()
21672176 if timeout > 0 :
21682177 monitor .cancel = NULL
21692178 monitor .cancel_this = NULL
21702179 monitor .set_deadline_msecs (timeout )
21712180 res = self ._baseapi .RecognizeForChopTest (& monitor )
21722181 else :
21732182 res = self ._baseapi .RecognizeForChopTest (NULL )
2183+ sig_off ()
21742184 return res == 0
21752185
21762186 cdef TessResultRenderer * _get_renderer (self , cchar_t * outputbase ):
@@ -2370,7 +2380,9 @@ cdef class PyTessBaseAPI:
23702380 """Return the recognized text coded as UTF-8 from the image."""
23712381 cdef char * text
23722382 with nogil :
2383+ sig_on ()
23732384 text = self ._baseapi .GetUTF8Text ()
2385+ sig_off ()
23742386 self ._destroy_pix ()
23752387 if text == NULL :
23762388 with gil :
@@ -2710,7 +2722,9 @@ def image_to_text(image, lang=_DEFAULT_LANG, PageSegMode psm=PSM_AUTO,
27102722 if pix == NULL :
27112723 with gil :
27122724 raise RuntimeError ('Failed to read picture' )
2725+ sig_on ()
27132726 text = _image_to_text (pix , clang , psm , cpath , oem )
2727+ sig_off ()
27142728 if text == NULL :
27152729 with gil :
27162730 raise RuntimeError (f'Failed to init API, possibly an invalid tessdata path: { path } ' )
@@ -2755,7 +2769,9 @@ def file_to_text(filename, lang=_DEFAULT_LANG, PageSegMode psm=PSM_AUTO,
27552769 if pix == NULL :
27562770 with gil :
27572771 raise RuntimeError ('Failed to read picture' )
2772+ sig_on ()
27582773 text = _image_to_text (pix , clang , psm , cpath , oem )
2774+ sig_off ()
27592775 if text == NULL :
27602776 with gil :
27612777 raise RuntimeError (f'Failed to init API, possibly an invalid tessdata path: { path } ' )
0 commit comments