用过MySQL的应该都知道,MySQL默认长链接只能保持8小时,超过后就会自动断开。
在peewee中如何维持长连接呢?
解决方法比较晦涩,需要自定义一个支持重试的mixin,然后自定义一种RetryMySQLDatabase混入mixin
from peewee import *
from peewee import __exception_wrapper__
class RetryOperationalError(object):
def execute[......]
用过MySQL的应该都知道,MySQL默认长链接只能保持8小时,超过后就会自动断开。
在peewee中如何维持长连接呢?
解决方法比较晦涩,需要自定义一个支持重试的mixin,然后自定义一种RetryMySQLDatabase混入mixin
from peewee import *
from peewee import __exception_wrapper__
class RetryOperationalError(object):
def execute[......]
def get_recursively(search_dict, field):
"""
Takes a dict with nested lists and dicts,
and searches all dicts for a key of the field
provided.
"""
fields_found = []
for key, value in search_dict.iteritems():[......]
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
print(s.getsockname()[0])
s.close()
备注:这个IP有可能被墙,可以换一个国内的,呵呵。。
如果是NAT出口的,显示的是NAT的IP地址。[......]
转载自:http://www.tuicool.com/articles/vIRryi
product 笛卡尔积
permutations 排列
combinations 组合,没有重复
combinations_with_replacement 组合,有重复
>>> import itertools
>>> for i in itertools.product('ABCD', repeat = 2):
... print[......]