Created
February 16, 2024 14:56
-
-
Save se7enack/a86abea95543d735f35860a340397de7 to your computer and use it in GitHub Desktop.
Python3 Threading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import time | |
import curses | |
import os | |
import threading | |
import subprocess | |
def waitforthis(thread): | |
scr = curses.initscr() | |
ani = ('\\', '|' ,'/', '-') | |
msg = f" {message} " | |
while thread.is_alive(): | |
for i in ani: | |
size = os.get_terminal_size() | |
width = size[0] | |
scr.addstr(0, 0, "".center(width, i)) | |
scr.addstr(1, 0, msg.center(width, i)) | |
scr.addstr(2, 0, "".center(width, i)) | |
scr.refresh() | |
time.sleep(.2) | |
scr.clear() | |
scr.refresh() | |
subprocess.run(["reset"]) | |
print(output) | |
def longrunningfunction(filename, size): | |
global message | |
global output | |
message = "Please Wait" | |
with open(filename, 'wb') as f: | |
f.write(bytes(size * 1024 * 1024 * 1024)) # write out a so many GB file | |
output = f"\n\n> Delete this junk {size}GB file: ./{filename}\n" | |
thread1 = threading.Thread(target=longrunningfunction, args=("deleteme.txt", 20)) # point target at any function that takes a long while | |
thread1.start() | |
waitforthis(thread1) # banner that says to wait while the fuction runs in the background |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment