Skip to content

Instantly share code, notes, and snippets.

@marco-brandizi
Last active August 15, 2022 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marco-brandizi/620a4cce9571205225c674d2272e0ddd to your computer and use it in GitHub Desktop.
Save marco-brandizi/620a4cce9571205225c674d2272e0ddd to your computer and use it in GitHub Desktop.
from threading import Thread
from time import sleep
# Support for background execution
alive_flag = True
def alive_msg_task ():
while alive_flag:
sleep ( 30 )
print ( "Still working, please wait...", end = " ", flush = True )
print ( "\nDownload completed" )
def download_task ( taxId, db ):
print ( "Building all-traits table, please wait...", end = " ", flush = True )
alive_flag = True
get_database_csv ( taxId, db )
alive_flag = False
# create dataframe for Tax IDs and their names
dframe_taxID = df_taxID()
print("Do you want to choose all the species or only one?")
@interact_manual
def all_one(All_One = ['All', 'One']):
if All_One == 'All':
for x, row in dframe_taxID.iterrows():
taxID = row['Tax IDs'] # get taxID
database = row['Database URL'] # get database url
get_database_csv(taxID, database) # get csv download link
else:
print("\nChoose the species name from the list below.")
@interact_manual
def show_taxid(Species = dframe_taxID['Tax Names']):
# get taxID and database url from the table
taxID = dframe_taxID[dframe_taxID['Tax Names'] == Species]['Tax IDs'].item()
database = dframe_taxID[dframe_taxID['Tax Names'] == Species]['Database URL'].item()
print("Tax ID is: " + taxID)
# get csv download link
download_thread = Thread ( target = download_task, name = "Downloader", args = [taxID, database] )
download_thread.start ()
# "I'm still alive" messages while the long-time task runs
alive_daemon = Thread ( daemon = True, target = alive_msg_task, name = "Alive Message Daemon" )
alive_daemon.start ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment