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 685 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  FTp timeout except korenron 2 3,601 Feb-01-2022, 06:51 AM
Last Post: korenron
  Calling a class from a function jc4d 5 1,835 Dec-17-2021, 09:04 PM
Last Post: ndc85430
  a function common to methods of a class Skaperen 7 2,638 Oct-04-2021, 07:07 PM
Last Post: Skaperen
  Tuple generator, and function/class syntax quazirfan 3 3,907 Aug-10-2021, 09:32 AM
Last Post: buran
  Class function is not running at all even though it is clearly run in the code SheeppOSU 2 2,123 Sep-26-2020, 10:54 PM
Last Post: SheeppOSU
  Test a class function via "unittest " Penguin827 1 1,626 Jul-10-2020, 08:31 AM
Last Post: Gribouillis
  Using input function in a Class wew044 2 2,297 Feb-06-2020, 03:08 AM
Last Post: wew044
  Appending a list in a class from a callback function snizbatch 5 3,755 Sep-01-2019, 06:27 AM
Last Post: snizbatch
  How to call base class function kamal_chennai 1 3,349 Apr-03-2019, 01:12 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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