Last active
April 16, 2024 15:06
-
-
Save mahdiPourkazemi/ba11b268cb47f7bbc7f1e45cf4a8f601 to your computer and use it in GitHub Desktop.
slow down your code with python decoration (used for network and etc)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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