Limiting the response time of a function

Asked

Viewed 258 times

1

I did a script on python 3 that performs speed tests on my internet every 60 seconds and writes these results in a file .txt.

Within this script I have a function called get_results which is the function responsible for performing the test of internet speed and return a Dict with the results obtained.
But if during the speed test my connection comes to fall the speed test does not end and my program keeps crashing, forcing me to manually stop it.

What I would like to do is set a time limit for the return of this function get_results and if at the stipulated time she did not return anything to me she would be interrupted and the script would continue with the normal flow of waiting another 60 seconds to perform the new test.

Code Source on Github Gist

  • https://stackoverflow.com/questions/492519/timeout-on-a-function-call

  • Put the code, at least those of the function.

  • I edited the question with the source code.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.