This file contains hidden or 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
CPU[| 0.4%] Tasks: 40, 53 thr; 1 running | |
Mem[||||||||||||||||||||||||||||||||||||||||||||||||||||||||338M/985M] Load average: 0.03 0.03 0.00 | |
Swp[ 0K/0K] Uptime: 00:31:48 | |
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command | |
1001 mysql 20 0 1134M 175M 14576 S 0.0 17.8 0:00.00 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid | |
1002 mysql 20 0 1134M 175M 14576 S 0.0 17.8 0:00.04 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid | |
1003 mysql 20 0 1134M 175M 14576 S 0.0 17.8 0:00.14 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid |
This file contains hidden or 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
fp = open(filename, 'w') | |
json.dump(data, fp) |
This file contains hidden or 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
def print_before(func): | |
def wrapped(*args, **kwds): | |
print('Before:', func.__name__, args, kwds) | |
return func(*args, **kwds) | |
return wrapped |
This file contains hidden or 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
@print_before | |
def important(lives, money, valuables=None): | |
"""Do big, important things!!""" | |
pass | |
>>> important(23, 105.17, valuables=['dogs']) | |
important (23, 105.17) {'valuables': ['dogs']} |
This file contains hidden or 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 | |
def print_before(func): | |
@functools.wraps(func) | |
def wrapped(*args, **kwds): | |
print(func.__name__, args, kwds) | |
return func(*args, **kwds) | |
This file contains hidden or 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
# WRONG | |
def print_before(func, label): | |
@functools.wraps(func) | |
def wrapped(*args, **kwds): | |
print(label, func.__name__, args, kwds) | |
return func(*args, **kwds) | |
return wrapped | |
This file contains hidden or 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
# Version 3 | |
def print_before2(label): | |
def decorator(func): | |
@functools.wraps(func) | |
def wrapped(*args, **kwds): | |
print(label, func.__name__, args, kwds) | |
return func(*args, **kwds) | |
This file contains hidden or 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
# Almost right | |
def print_before3(label='DEBUG:'): | |
def decorator(func): | |
@functools.wraps(func) | |
def wrapped(*args, **kwds): | |
print(label, func.__name__, args, kwds) | |
return func(*args, **kwds) | |
This file contains hidden or 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
@print_before3() | |
def important(lives, money, valuables=None): | |
pass | |
@print_before3('BORING:') | |
def dull(*args, **kwds): | |
pass | |
This file contains hidden or 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
@print_before3() | |
def mj1(a, b, c): | |
pass | |
@print_before3('OK') | |
def mj2(one, two, three): | |
pass | |