0

I have a function that depends on the internet and downloads files, however sometimes the download time is too long or the sending request processes is failing.I wanted to know how can I set some-thing like a timer for the function, and if it exceeds the time (lets say a minute) to rerun the function from the beginning.

Maxim Dunavicher
  • 635
  • 8
  • 19

1 Answers1

2

Use signal for time out cases

First set the signal handler with signal.signal(signal.SIGALRM, handler)

To set the time for the signal alarm use signal.alarm(seconds)

If the request to download is taking too long, i.e more than the seconds specified in alarm, the handler will be called upon

You could check out the documentation.

Hannes Ovrén
  • 21,229
  • 9
  • 65
  • 75
Prasanth Louis
  • 4,658
  • 2
  • 34
  • 47