Mddct / wenet-binding

wenet runtime binding
5 stars 1 forks source link

python GIl issues c++ thread #3

Open Mddct opened 2 years ago

Mddct commented 2 years ago

https://github.com/pybind/pybind11/issues/1723

Mddct commented 2 years ago

[{"sentence":"甚至"}] [{"sentence":"甚至出现"}] [{"sentence":"甚至出现交易几"}] [{"sentence":"甚至出现交易几乎停滞"}] [{"sentence":"甚至出现交易几乎停滞的情"}]

decoder = wenet.StreammingAsrDecoder(model)
# simulating streamming
def send():
        # decoder.AcceptWaveform(b, True)
        # return
        nbytes = int((16000/1000)*2*800)
        final = False
        r = nbytes
        l = 0
        while True:
                if r == len(b):
                        final = False
                        l = 0
                        r = nbytes
                decoder.AcceptWaveform(b[l:r], final)

                l = r
                if l >= len(b):
                        break

                if r + nbytes < len(b):
                        r = r + nbytes
                else:
                        r = len(b)

t = threading.Thread(target=send)
t.start()
#send()
#decoder.Reset()
#decoder.Reset()
#send()

for res in decoder.GetInstanceResult():
        print(str(res))
t.join()

when gil is hold in send thread, these is no chance running "for res in decoder.GetInstanceResult():" so if AcceptWaveform is passing to c++, c++ code should release gil lock in some way

Mddct commented 2 years ago

resolved by https://github.com/Mddct/wenet-binding/blob/python-streamming/python/py_asr_wrapper.cc#L61-L65

Mddct commented 2 years ago

resolved by https://github.com/Mddct/wenet-binding/blob/python-streamming/python/py_asr_wrapper.cc#L61-L65

link is broken, see https://github.com/Mddct/wenet-binding/blob/develop/python/py_asr_wrapper.cc#L61-L65