Last active
February 2, 2023 12:30
-
-
Save the-moog/94b09b49232731bd2a3cedd24501e23b to your computer and use it in GitHub Desktop.
Thank you for this ! Only snippet that I managed to achieve what I wanted to do with !
For anyone seeking a more minimalized, technical example:
import threading
from IPython.display import display
import ipywidgets as widgets
import time
from zmq.eventloop.ioloop import IOLoop
progress = widgets.FloatProgress(value=0, min=0, max=10)
display(progress)
def run(progress, ioloop):
def update_progress(i, progress=progress):
progress.value = i
for i in range(10):
time.sleep(1)
ioloop.add_callback(update_progress, i)
def run_progress(*args, **kwargs):
thread = threading.Thread(target=run, args=(progress, IOLoop.instance()))
thread.start()
button = widgets.Button(description="Start")
button.on_click(run_progress)
display(button)
Also I suggest importing IOLoop directly from tornado, since that's what's used by jupyter, and there's no need to install zmq to get it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this is emulating what the Python 3 Asyncio module does, I'll try and write a version that uses that instead