I am developing a Python application by calling the C ++ DLL, I have placed my interaction between my DLL and Python 3.4 here . But now I need to do some streaming process using a thread-based model, and my callback function seems to queue all print , and only when my streaming has finished all information is printed.
def callbackU(OutList, ConList, nB): for i in range(nB): out_list_item = cast(OutList[i], c_char_p).value print("{}\t{}".format(ConList[i], out_list_item)) return 0
I tried using the following methods, but they all work the same way:
from threading import Lock print_lock = Lock() def save_print(*args, **kwargs): with print_lock: print (*args, **kwargs) def callbackU(OutList, ConList, nB): for i in range(nB): out_list_item = cast(OutList[i], c_char_p).value save_print(out_list_item)) return 0
and
import sys def callbackU(OutList, ConList, nB): for i in range(nB): a = cast(OutList[i], c_char_p).value sys.stdout.write(a) sys.stdout.flush() return 0
I would like my callback to print its message when it is called, and not when the whole process ends.
source share