py: fix protential deadlock for python binding