After some investigation, I think I found the culprit:
it's print
I think the problem is that iClone is monitoring print (possibly redirected their stdout) to output to their UI console. And when another thread tries to print or logging.info etc., it attempts to output on UI thread, and that's a big no-no and can lead to weird race conditions and crashes.
So, it seems, we cannot use print statements in our background threads, unless Reallusion redesign their Python logging to be thread safe.
For now as a workaround I implement my own thread safe wrapper around print that dispatches it back to the main Qt thread through its Signal queue:
class DummyWorker(QThread) :
# Signals must be class vars
logger_emiter = Signal(str)
def __init__(self):
super().__init__()
# send to the main thread explicitly
self.logger_emiter.connect(self.main_log, Qt.QueuedConnection)
print("DummyWorker created")
@Slot(str)
def main_log(self, s):
# logging must be on the main thread,
# else iClone crashes because it logs to UI thread
print(s)
def run(self) :
time.sleep(2)
#print(f"worker finished.") crashes - no printing from another thread in iClone!
self.logger_emiter.emit("DummyWorker slept")
Edited
4 Years Ago by
midix