Created
February 4, 2019 18:34
-
-
Save audebert/67440b19258658d58d983be635ad3ca0 to your computer and use it in GitHub Desktop.
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
Disassembly of bar: | |
11 0 LOAD_GLOBAL 0 (print) | |
2 LOAD_CONST 1 ('bar') | |
4 CALL_FUNCTION 1 | |
6 POP_TOP | |
8 LOAD_CONST 0 (None) | |
10 RETURN_VALUE | |
Disassembly of delayed: | |
18 0 LOAD_GLOBAL 0 (time) | |
2 LOAD_METHOD 1 (sleep) | |
4 LOAD_CONST 1 (1) | |
6 CALL_METHOD 1 | |
8 POP_TOP | |
19 10 LOAD_GLOBAL 2 (func) | |
12 CALL_FUNCTION 0 | |
14 POP_TOP | |
16 LOAD_CONST 0 (None) | |
18 RETURN_VALUE | |
Disassembly of foo: | |
7 0 LOAD_GLOBAL 0 (print) | |
2 LOAD_CONST 1 ('foo') | |
4 CALL_FUNCTION 1 | |
6 POP_TOP | |
8 LOAD_CONST 0 (None) | |
10 RETURN_VALUE | |
Disassembly of func: | |
11 0 LOAD_GLOBAL 0 (print) | |
2 LOAD_CONST 1 ('bar') | |
4 CALL_FUNCTION 1 | |
6 POP_TOP | |
8 LOAD_CONST 0 (None) | |
10 RETURN_VALUE |
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 functools | |
import time | |
import threading | |
def foo(): | |
print('foo') | |
def bar(): | |
print('bar') | |
for func in [foo, bar]: | |
@functools.wraps(func) | |
def delayed(): | |
time.sleep(1) | |
func() | |
t = threading.Thread(target=delayed) | |
t.daemon = True | |
t.start() | |
time.sleep(2) | |
# Output: | |
# bar | |
# bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment