Skip to content

Instantly share code, notes, and snippets.

View timothymugayi's full-sized avatar
🎯
Focusing

Timothy Mugayi timothymugayi

🎯
Focusing
View GitHub Profile
@timothymugayi
timothymugayi / tqdm_nested_loops.py
Last active December 1, 2019 02:00
Tqdm nested loops
import time
import sys
from tqdm import trange
def do_something():
time.sleep(1)
def do_another_something():
time.sleep(1)
@timothymugayi
timothymugayi / tqdm_manual_progress_bar.py
Created December 1, 2019 02:55
tqdm update progress bar manually
import time
import sys
from tqdm import tqdm
def do_something():
time.sleep(1)
with tqdm(total=100, file=sys.stdout) as pbar:
# Copyright 2019 tiptapcode Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@timothymugayi
timothymugayi / tqdm_pandas_dataframe.py
Last active December 6, 2019 15:34
Example how to display a progress bar with tqdm in Pandas Dataframe
import time
import pandas as pd
import requests
from tqdm import tqdm
def percent_off(product_price, discount):
try:
discount = float(discount)
@timothymugayi
timothymugayi / tqdm_colors.py
Created December 6, 2019 15:33
Tqdm colors with colorama Cross-platform colored terminal text
from tqdm import trange
from colorama import Fore
# Cross-platform colored terminal text.
color_bars = [Fore.BLACK,
Fore.RED,
Fore.GREEN,
Fore.YELLOW,
Fore.BLUE,
Fore.MAGENTA,
@timothymugayi
timothymugayi / tqdm_threadpool.py
Created December 6, 2019 15:37
How to run tqdm in multiple threads
import time
from random import randrange
from multiprocessing.pool import ThreadPool
from tqdm import tqdm
def func_call(position, total):
text = 'progressbar #{position}'.format(position=position)
@timothymugayi
timothymugayi / tqdm_write_log.py
Created December 8, 2019 01:19
How to use python logger with tqdm
# Copyright 2019 tiptapcode Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@timothymugayi
timothymugayi / tqdm_subprocess.py
Created December 10, 2019 16:41
Tqdm elapsed time with python subprocesses
import sys
import subprocess
from tqdm import tqdm
def create_test_bash_script():
"""
Create a bash script that generates numbers 1 to 1000000
This is just for illustration purpose to simulate a long running bash command
@timothymugayi
timothymugayi / shared_dict_update.py
Last active April 7, 2022 11:05
How to update python multiprocessing shared dict
import uuid
import sys
import multiprocessing
lock = multiprocessing.Lock()
if __name__ == '__main__':
print(sys.version);
# Manager().dict() = is a dict that spans multiple processes it exists in shared memory
import time
def run_me_now():
print("Am running")
time.sleep(3) # suspends execution for the given number of seconds
print("Am still running")
time.sleep(3)