аватар question@mail.ru · 01.01.1970 03:00

How to start the function again if an exception falls?

The function is given with the exception to be inside. If the exception does not fall, then the function works further.

How to start the function again if the exception falls?

аватар answer@mail.ru · 01.01.1970 03:00

In the code:

  • try_repeat & ndash; The decorator that repeats the function of the function if she threw out the exception. A function that with a probability of 50% will throw out the exclusion

Example:

   def   try_repeat  ( funch ):   def  ):  Count =  10    While  count:   try :   Retu  FUNC (*arg, ** kwargs)   except  expereption  as  e:   Print  ( 'error:' , e)  count -=  1    retu  wrapper @try_repeat    def   exception_func  ():   import  random  if  radom.randint ( 0 ,  1 ):   raise  experiment ( '!!!' ) exception_funk ()                                       

Latest

Similar