From 226124956cf17998cd55da4db9a536bf2cfc3036 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 19 Dec 2016 10:41:27 -0800 Subject: [PATCH] Allow timeout decorator to handle @timeout as well as @timeout() --- lib/ansible/module_utils/facts.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index d8223b90be..40b57c4c21 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -101,6 +101,19 @@ def timeout(seconds=None, error_message="Timer expired"): return wrapper + # If we were called as @timeout, then the first parameter will be the + # function we are to wrap instead of the number of seconds. Detect this + # and correct it by setting seconds to our default value and return the + # inner decorator function manually wrapped around the function + if callable(seconds): + func = seconds + seconds = 10 + return decorator(func) + else: + # If we were called as @timeout([...]) then python itself will take + # care of wrapping the inner decorator around the function + return decorator + return decorator # --------------------------------------------------------------