fixed python GIL reacquire in case of exception
This commit is contained in:
parent
466345e936
commit
f6fec7ad2f
@ -37,9 +37,22 @@ static int failmsg(const char *fmt, ...)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PyAllowThreads
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PyAllowThreads() : _state(PyEval_SaveThread()) {}
|
||||||
|
~PyAllowThreads()
|
||||||
|
{
|
||||||
|
PyEval_RestoreThread(_state);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
PyThreadState* _state;
|
||||||
|
};
|
||||||
|
|
||||||
#define ERRWRAP2(expr) \
|
#define ERRWRAP2(expr) \
|
||||||
try \
|
try \
|
||||||
{ \
|
{ \
|
||||||
|
PyAllowThreads allowThreads; \
|
||||||
expr; \
|
expr; \
|
||||||
} \
|
} \
|
||||||
catch (const cv::Exception &e) \
|
catch (const cv::Exception &e) \
|
||||||
@ -105,22 +118,6 @@ static inline int* refcountFromPyObject(const PyObject* obj)
|
|||||||
return (int*)((size_t)obj + REFCOUNT_OFFSET);
|
return (int*)((size_t)obj + REFCOUNT_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
class PyAllowThreads
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PyAllowThreads() : _state(PyEval_SaveThread())
|
|
||||||
{
|
|
||||||
//printf("+GIL\n");
|
|
||||||
}
|
|
||||||
~PyAllowThreads()
|
|
||||||
{
|
|
||||||
PyEval_RestoreThread(_state);
|
|
||||||
//printf("-GIL\n");
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
PyThreadState* _state;
|
|
||||||
};
|
|
||||||
|
|
||||||
class NumpyAllocator : public MatAllocator
|
class NumpyAllocator : public MatAllocator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -19,10 +19,7 @@ gen_template_parse_args = Template("""const char* keywords[] = { $kw_list, NULL
|
|||||||
gen_template_func_body = Template("""$code_decl
|
gen_template_func_body = Template("""$code_decl
|
||||||
$code_parse
|
$code_parse
|
||||||
{
|
{
|
||||||
{
|
$code_fcall;
|
||||||
PyAllowThreads allow;
|
|
||||||
$code_fcall;
|
|
||||||
}
|
|
||||||
$code_ret;
|
$code_ret;
|
||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user