0

In my python code I have

Class Download()

Download() can download a txt file with link given.

Now I want to call the Download() class say 3 times with 3 different links one by one and give the system 2 minutes.

I would want to have the output of the Download() in a variable appended. If in the event of timeout one class can't complete the task it will be ignored and not added to the master variable.

I saw some coding with Thread Timeout etc.

I know people might down vote me for duplicate and all but I just want to get a direction on how I approach the whole thing.

Could someone give some quick hint on how I run the class with Threading with arguments passing and give a timeout and get output after the timeout of completed instances. Thanks in advance.

def timed_join_all(threads, timeout):
    start = cur_time = time.time()
    while cur_time <= (start + timeout):
        for thread in threads:
            if not thread.is_alive():
                thread.join()
        time.sleep(1)
        cur_time = time.time()

if __name__ == '__main__':
    for thread in threads:
        thread.start()

timed_join_all(threads, 60)

I saw this code in some QA but can't figure where Threads came from and can't figure how to get the Thread output in a variable.

Abul Hasnat
  • 1,541
  • 2
  • 16
  • 23

0 Answers0