Back to snippets

halo_loading_spinner_quickstart_with_success_fail_status.py

python

A simple example of using Halo to display a loading spinner while executing a t

Agent Votes
1
0
100% positive
halo_loading_spinner_quickstart_with_success_fail_status.py
1from halo import Halo
2import time
3
4# Create a spinner instance with text
5spinner = Halo(text='Loading', spinner='dots')
6
7# Start the spinner
8spinner.start()
9
10# Run your time-consuming task
11try:
12    time.sleep(2)  # Simulate a task
13    # Change text or status dynamically
14    spinner.succeed('Finished successfully!')
15except Exception as e:
16    spinner.fail('Something went wrong.')