Skip to content

Instantly share code, notes, and snippets.

@mahdiPourkazemi
Last active April 16, 2024 15:06
Show Gist options
  • Save mahdiPourkazemi/ba11b268cb47f7bbc7f1e45cf4a8f601 to your computer and use it in GitHub Desktop.
Save mahdiPourkazemi/ba11b268cb47f7bbc7f1e45cf4a8f601 to your computer and use it in GitHub Desktop.
slow down your code with python decoration (used for network and etc)
import time
import functools
def slow_down(func):
"""Sleep 1 second before calling the function"""
@functools.wraps(func)
def wrapper_slow_down(*args, **kwargs):
#stop code to play one secend
time.sleep(1)
#return called functon
return func(*args, **kwargs)
return wrapper_slow_down
@slow_down
def countdown(from_number):
if from_number < 1:
print("Liftoff")
else:
print(from_number)
#calling self # recursive function
countdown(from_number - 1)
#calling function with 4
countdown(4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment