Prolog may be called safely from any Python thread. The Prolog
execution is embraced with Py_BEGIN_ALLOW_THREADS
and
Py_END_ALLOW_THREADS
, which implies that Python is allowed
to switch to another thread while Prolog is doing its work.
If the calling Python thread is not the one that initiated Janus, janus.query_once() and janus.query() attach and detach a temporary Prolog engine using PL_thread_attach_engine() and PL_thread_destroy_engine(). This is relatively costly. In addition we allow associating a Prolog engine persistently with the calling thread.
NULL
to PL_thread_attach_engine().
Future versions may provide access to the creation attributes.
If the thread already has an engine the attach count is incremented and the current engine id is returned. The engine is detached after a matching number of calls to janus.detach_engine()