Skip to content

Instantly share code, notes, and snippets.

@the-moog
Last active February 2, 2023 12:30
Show Gist options
  • Save the-moog/94b09b49232731bd2a3cedd24501e23b to your computer and use it in GitHub Desktop.
Save the-moog/94b09b49232731bd2a3cedd24501e23b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Ivorforce
Copy link

Ivorforce commented Dec 11, 2020

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)

@sapristi
Copy link

sapristi commented Dec 12, 2020

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