本文整理汇总了Python中dht.DHT.run方法的典型用法代码示例。如果您正苦于以下问题:Python DHT.run方法的具体用法?Python DHT.run怎么用?Python DHT.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dht.DHT
的用法示例。
在下文中一共展示了DHT.run方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from dht import DHT [as 别名]
# 或者: from dht.DHT import run [as 别名]
def main(n_processes, fill, test, needs_server):
for _ in xrange(n_processes):
try:
seed = random.choice(kads).node
except IndexError:
seed = None
node = Node(random_32bytes(), port=next(ports))
dht = DHT(node, seed, context=context)
kads.append(dht)
processes.append(dht.run())
print "%s started." % node
if fill:
with open('./lipsum.txt') as f:
result = re.findall("[A-Z]{2,}(?![a-z])|[A-Z][a-z]+(?=[A-Z])|[\'\w\-]+", f.read())
for idx in xrange(1, len(result)):
first, second = result[idx-1], result[idx]
random.choice(kads)[first] = second
if test:
n_failures = 0
for idx in xrange(1, len(result)):
first, second = result[idx-1], result[idx]
try:
print "%s -> %s" % (first, random.choice(kads)[first])
except KeyError:
n_failures += 1
print "Failed %s times" % n_failures
if needs_server:
app.run()
示例2: create
# 需要导入模块: from dht import DHT [as 别名]
# 或者: from dht.DHT import run [as 别名]
def create():
node = Node(random_32bytes(), port=next(ports))
seed = random.choice(kads).node
dht = DHT(node, seed, context=context)
kads.append(dht)
processes.append(dht.run())
return json.dumps({
'n': len(processes)-1
})