swig: Add %thread directive for repo_sack.hpp for Python

The purpose is to enable multithread support in python. With the %thread
directive, the Python GIL is released before entering the methods from
repo_sack.hpp and acquired when exiting them. In case the methods are
called in a thread, another thread is not blocked by it. This is
especially important in case of loading repositories which can take
a lot of time.
This commit is contained in:
Pavla Kratochvilova 2025-06-23 15:10:31 +02:00 committed by Petr Pisar
parent 3fb6c85464
commit 54fabbcd4b
1 changed files with 6 additions and 1 deletions

View File

@ -1,5 +1,6 @@
#if defined(SWIGPYTHON)
%module(package="libdnf5", directors="1") repo
%module("threads"=1, package="libdnf5", directors="1") repo
%nothread;
#elif defined(SWIGPERL)
%module "libdnf5::repo"
#elif defined(SWIGRUBY)
@ -153,6 +154,10 @@ wrap_unique_ptr(RepoCallbacksUniquePtr, libdnf5::repo::RepoCallbacks);
%include "libdnf5/repo/repo_query.hpp"
%template(SackRepoRepoQuery) libdnf5::sack::Sack<libdnf5::repo::Repo>;
#if defined(SWIGPYTHON)
%thread;
#endif
%include "libdnf5/repo/repo_sack.hpp"
%template(RepoSackWeakPtr) libdnf5::WeakPtr<libdnf5::repo::RepoSack, false>;