0

I have a function that reads in text files and parses them and I would like to write the parsed results to a csv file. How do you get result from a thread?

def parse_txt_file(file_path):
    with open(file_path,'r') as f:
        # parse all the data here
        # this can take long.....
        return parsed_data

def loading_animation(process):
    while process.is_alive():
        # do some stuff

def generate_csv(parsed_data):
    # write to csv file

def main():
    my_thread = threading.Thread(target=parse_txt_file,args=(file_path,))
    my_thread.start()
    loading_animation(my_thread)
    my_thread.join()

# At this point I want to get the parsed data from the my_thread
# and call generate_csv()
generate_csv(parsed_data)  # <-- How to get the the parsed data from my_thread?
magicsword
  • 1,071
  • 2
  • 15
  • 24

0 Answers0