Commit f6fec7ad authored by Alexander Mordvintsev's avatar Alexander Mordvintsev

fixed python GIL reacquire in case of exception

parent 466345e9
......@@ -37,9 +37,22 @@ static int failmsg(const char *fmt, ...)
return 0;
}
class PyAllowThreads
{
public:
PyAllowThreads() : _state(PyEval_SaveThread()) {}
~PyAllowThreads()
{
PyEval_RestoreThread(_state);
}
private:
PyThreadState* _state;
};
#define ERRWRAP2(expr) \
try \
{ \
PyAllowThreads allowThreads; \
expr; \
} \
catch (const cv::Exception &e) \
......@@ -105,22 +118,6 @@ static inline int* refcountFromPyObject(const PyObject* obj)
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
{
public:
......
......@@ -19,10 +19,7 @@ gen_template_parse_args = Template("""const char* keywords[] = { $kw_list, NULL
gen_template_func_body = Template("""$code_decl
$code_parse
{
{
PyAllowThreads allow;
$code_fcall;
}
$code_fcall;
$code_ret;
}
""")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment