Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why i cant use func_timeout in method a class in python #35

Open
angushhz opened this issue Nov 15, 2024 · 0 comments
Open

Why i cant use func_timeout in method a class in python #35

angushhz opened this issue Nov 15, 2024 · 0 comments

Comments

@angushhz
Copy link

angushhz commented Nov 15, 2024

I have a code using func_timeout to limit time out of process = 0.1
Example

class  Solution
         def process_timeout(self, s: str):
        // run some task take time
        return {
            "province": province,
            "district": district,
            "ward": original_ward, # Duy Fix khac dau
        }
    def process(self, s: str):
       res = self.process_timeout(s)
        return res

In main function:

🙋‍♂️ Happy case:
In this case func_timeout run ok . It will limit timeout in 0.1s

__main___
solution = Solution()
for i in Range(10):
  try:
          res = func_timeout(0.1,solution.process,args=(s,))
  except FunctionTimedOut:
          return {            
                    "province": "EXCEPTION",
                    "district": "EXCEPTION",
                    "ward": "EXCEPTION"
                  }

👎👎 Bad case change liitle logic :👎
I move function func_timeout to inside method process. It dont run or call thread to set timeout. It can't kill thread after 0.1s.

class Solution:
  // same sample code
     ....
    def process(self, s: str):
      try:
        res = func_timeout(0.1,self.process_timeout,args=(s,))
        return res
     except FunctionTimedOut:
          return {            
                    "province": "EXCEPTION",
                    "district": "EXCEPTION",
                    "ward": "EXCEPTION"
                  }


__ main __
solution = Solution()
for i in Range(10):
     res = solution.process()

😑
Please help me answer above situation ? thanks 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant