Skip to content

Commit

Permalink
Refactor python progress callback (#266)
Browse files Browse the repository at this point in the history
* refactor the compiler progress callback

* Update autwrap_workarounds.pyx
  • Loading branch information
hendrikmuhs authored Dec 28, 2023
1 parent 71ecb56 commit d4101a6
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 14 deletions.
7 changes: 1 addition & 6 deletions python/src/addons/CompletionDictionaryCompiler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,4 @@

cdef void* callback = <void*> args[0]
with nogil:
self.inst.get().Compile(callback_wrapper, callback)


# definition for all compilers
cdef void callback_wrapper(size_t a, size_t b, void* py_callback) with gil:
(<object>py_callback)(a, b)
self.inst.get().Compile(progress_compiler_callback, callback)
2 changes: 1 addition & 1 deletion python/src/addons/FloatVectorDictionaryCompiler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

cdef void* callback = <void*> args[0]
with nogil:
self.inst.get().Compile(callback_wrapper, callback)
self.inst.get().Compile(progress_compiler_callback, callback)

2 changes: 1 addition & 1 deletion python/src/addons/IntDictionaryCompiler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

cdef void* callback = <void*> args[0]
with nogil:
self.inst.get().Compile(callback_wrapper, callback)
self.inst.get().Compile(progress_compiler_callback, callback)

2 changes: 1 addition & 1 deletion python/src/addons/IntDictionaryCompilerSmallData.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

cdef void* callback = <void*> args[0]
with nogil:
self.inst.get().Compile(callback_wrapper, callback)
self.inst.get().Compile(progress_compiler_callback, callback)

2 changes: 1 addition & 1 deletion python/src/addons/JsonDictionaryCompiler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

cdef void* callback = <void*> args[0]
with nogil:
self.inst.get().Compile(callback_wrapper, callback)
self.inst.get().Compile(progress_compiler_callback, callback)

2 changes: 1 addition & 1 deletion python/src/addons/JsonDictionaryCompilerSmallData.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@

cdef void* callback = <void*> args[0]
with nogil:
self.inst.get().Compile(callback_wrapper, callback)
self.inst.get().Compile(progress_compiler_callback, callback)

2 changes: 1 addition & 1 deletion python/src/addons/KeyOnlyDictionaryCompiler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

cdef void* callback = <void*> args[0]
with nogil:
self.inst.get().Compile(callback_wrapper, callback)
self.inst.get().Compile(progress_compiler_callback, callback)

2 changes: 1 addition & 1 deletion python/src/addons/StringDictionaryCompiler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

cdef void* callback = <void*> args[0]
with nogil:
self.inst.get().Compile(callback_wrapper, callback)
self.inst.get().Compile(progress_compiler_callback, callback)

5 changes: 5 additions & 0 deletions python/src/addons/autwrap_workarounds.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ def get_interpreter_executable():
executable = executable.encode('utf-8')

return executable


# definition for all compilers
cdef void progress_compiler_callback(size_t a, size_t b, void* py_callback) noexcept with gil:
(<object>py_callback)(a, b)
2 changes: 1 addition & 1 deletion python/src/pxds/match.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cdef extern from "keyvi/dictionary/match.h" namespace "keyvi::dictionary":
void SetScore(float score)
libcpp_utf8_output_string GetMatchedString()
void SetMatchedString (libcpp_utf8_string matched_string)
PyObject* GetAttributePy(libcpp_utf8_string) nogil except + # wrap-ignore
PyObject* GetAttributePy(libcpp_utf8_string) except + nogil # wrap-ignore
libcpp_utf8_output_string GetValueAsString() except +
libcpp_string GetRawValueAsString() except +
libcpp_string GetMsgPackedValueAsString() except + # wrap-ignore
Expand Down

0 comments on commit d4101a6

Please sign in to comment.