Python Forum
TimeOut a function in a class ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TimeOut a function in a class ?
#1
Hey everyone !

Here is my problem : I have defined a class, where I have defined some functions. In the __init__ of my class I can call some of the defined functions . The problem is that some of these functions can sometimes take a long time to execute. How can I set a timeout in these functions, so that they stop if they take too long?

For example :

class test:
def __init__(self):
self.do_actions_1()
self.do_actions_2()

def do_actions_1(self):
"bla bla bla bla bla"
def do_actions_2(self):
"bla bla bla bla bla"

If one of these actions takes too long, how can I stop it?

Thank you for your answer! :)
Reply
#2
There are some projects to do that in Pypi, such as timeout-decorator
Armandito likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  The function of double underscore back and front in a class function name? Pedroski55 9 2,412 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  How to timeout a task using the ThreadpoolExecutor? lowercase00 2 5,233 Feb-07-2023, 05:44 PM
Last Post: deanhystad
  FTp timeout except korenron 2 5,345 Feb-01-2022, 06:51 AM
Last Post: korenron
  Calling a class from a function jc4d 5 2,863 Dec-17-2021, 09:04 PM
Last Post: ndc85430
  a function common to methods of a class Skaperen 7 3,967 Oct-04-2021, 07:07 PM
Last Post: Skaperen
  Tuple generator, and function/class syntax quazirfan 3 6,621 Aug-10-2021, 09:32 AM
Last Post: buran
  printing contents of Jar on timeout Rakshan 1 2,283 Jul-30-2021, 07:48 AM
Last Post: buran
  Class function is not running at all even though it is clearly run in the code SheeppOSU 2 3,489 Sep-26-2020, 10:54 PM
Last Post: SheeppOSU
  Test a class function via "unittest " Penguin827 1 2,190 Jul-10-2020, 08:31 AM
Last Post: Gribouillis
  Using input function in a Class wew044 2 2,911 Feb-06-2020, 03:08 AM
Last Post: wew044

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020