import threading import time threading.Thread = mo.Thread def run_long(): while True: print("looping") time.sleep(1) bar = threading.Thread(target=run_long) bar.start()
bar.join()
could help. The output would be kept in the cell / different cell.import threading import time # Override the Thread class with a custom Thread class threading.Thread = mo.Thread def run_thread_with_sleep(): print("bar") time.sleep(2) print("foo") # Create a new thread that runs the function foo = threading.Thread(target=run_thread_with_sleep) foo.start()