- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我写了一些查询 adns 的代码。这段代码的问题是它卡住了,怎么办?让我解释一下:
您认为可能导致此问题的原因是什么以及如何解决?
Inside class's init'
Data
host www.yahoo.com
dnslist length 5
intensity 1
Inside resolve()
inside finished_resolving()
Resolved : 0/5
Inside 'while not finished_resolving'
Queue: 0/1
Launching Querying for www.yahoo.com/1 on 192.168.50.1
Queue: 1/1
Launching Querying for www.yahoo.com/1 on 208.67.222.222
inside collect_results()
inside finished_resolving()
Resolved : 0/5
Inside 'while not finished_resolving'
------------------------ CLIPPED ----------------
Inside 'while not finished_resolving'
inside collect_results()
Inside collect_results's for query in self.adns.completed()
DNS used was208.67.222.222
Answered : (0, 'any-fp.wa1.b.yahoo.com', 1286169807, ('69.147.125.65', '67.195.160.76'))
Resolved www.yahoo.com to 69.147.125.65 using 208.67.222.222
Resolved hosts count1
And they are:
{'208.67.222.222': '69.147.125.65'}
inside finished_resolving()
Resolved : 1/5
Inside 'while not finished_resolving'
Queue: 1/1
Launching Querying for www.yahoo.com/1 on 208.67.220.220
inside collect_results()
inside finished_resolving()
Resolved : 1/5
Inside 'while not finished_resolving'
-------------------------- CLIPPED --------------------
inside collect_results()
Inside collect_results's for query in self.adns.completed()
DNS used was208.67.220.220
Answered : (0, 'any-fp.wa1.b.yahoo.com', 1286169790, ('67.195.160.76', '69.147.125.65'))
Resolved www.yahoo.com to 67.195.160.76 using 208.67.220.220
Resolved hosts count2
And they are:
{'208.67.222.222': '69.147.125.65', '208.67.220.220': '67.195.160.76'}
inside finished_resolving()
Resolved : 2/5
Inside 'while not finished_resolving'
Queue: 1/1
Launching Querying for www.yahoo.com/1 on 8.8.8.8
inside collect_results()
inside finished_resolving()
Resolved : 2/5
Inside 'while not finished_resolving'
-------------------------- CLIPPED --------------------
inside collect_results()
Inside collect_results's for query in self.adns.completed()
DNS used was8.8.8.8
Answered : (0, 'eu-fp.wa1.b.yahoo.com', 1286169758, ('87.248.122.122',))
Resolved www.yahoo.com to 87.248.122.122 using 8.8.8.8
Resolved hosts count3
And they are:
{'208.67.222.222': '69.147.125.65', '208.67.220.220': '67.195.160.76', '8.8.8.8': '87.248.122.122'}
inside finished_resolving()
Resolved : 3/5
Inside 'while not finished_resolving'
Queue: 1/1
Launching Querying for www.yahoo.com/1 on 8.8.4.4
inside collect_results()
inside finished_resolving()
Resolved : 3/5
Inside 'while not finished_resolving'
-------------------- CLIPPED -------------------------------------
inside collect_results()
Inside collect_results's for query in self.adns.completed()
DNS used was8.8.4.4
Answered : (0, 'eu-fp.wa1.b.yahoo.com', 1286169757, ('87.248.122.122',))
Resolved www.yahoo.com to 87.248.122.122 using 8.8.4.4
Resolved hosts count4
And they are:
{'208.67.222.222': '69.147.125.65', '208.67.220.220': '67.195.160.76', '8.8.8.8': '87.248.122.122', '8.8.4.4': '87.248.122.122'}
inside finished_resolving()
Resolved : 4/5
Inside 'while not finished_resolving'
inside collect_results()
inside finished_resolving()
Resolved : 4/5
---------------- CLIPPED -------------------------------
(最后一个 block 不断重复,直到系统开始挂起,负载上升到 24)
测试.py
import adns
from time import time
from async_dns import AsyncResolver
dnslist2 = ["8.8.4.4", "8.8.8.8", "208.67.220.220", "208.67.222.222", "192.168.50.1"] #192.168.50.1 is a dns server i manage
host = "www.yahoo.com"
record = adns.rr.A
intensity = len(dnslist2)/5+1
ar = AsyncResolver(dnslist2, host, record, intensity)
start = time()
resolved = ar.resolve()
end = time()
print "\n\n"
for dns, ip in resolved.items():
if ip is None:
print "%s could not resolv %s." % (dns, host)
else:
print "%s resolved it to %s : %s" % (dns, host, ip)
print "\n\n----------------------------------------------------"
print "It took %.2f seconds to query %d dns." % (end-start, len(dnslist))
print "----------------------------------------------------"
async_dns.py
#!/usr/bin/python
#
import sys
import adns
from time import time
class AsyncResolver(object):
def __init__(self, dnslist, host, record, intensity=10):
"""
dnslist: a list of dns used to resolve
host : hostname to resolve
record: recordtype to resolve
intensity: how many hosts to resolve at once
"""
print "Inside class's init'"
self.dnslist = dnslist
self.host = host
self.record = record
if intensity >= len(dnslist) :
self.intensity = len(dnslist)/5+1
else:
self.intensity = intensity
print "Data"
print "host " + host
print "dnslist length " + str(len(dnslist))
print "intensity " + str(intensity)
def resolve(self):
""" Resolves hosts and returns a dictionary of { 'dns': 'ip' }. """
print "Inside resolve()"
host = self.host
record = self.record
resolved_hosts = {}
active_queries = {}
dns_queue = self.dnslist[:]
def collect_results():
print "inside collect_results()"
for query in self.adns.completed():
print "Inside collect_results's for query in self.adns.completed()"
answer = query.check()
dns = active_queries[query]
print "DNS used was" + dns
print "Answered : " + str(answer)
del active_queries[query]
if answer[0] == 0:
#print "Inside answer[0] == 0 , ip:" + answer[3][0]
ip = answer[3][0]
resolved_hosts[dns] = ip
print "Resolved %s to %s using %s" % (host, ip, dns)
print "Resolved hosts count" + str(len(resolved_hosts))
print "And they are: "
print str(resolved_hosts)
print "\n"
elif answer[0] == 101 and not record == adns.rr.CNAME: # CNAME if CNAME wasn't required'
print "ooopppps, i got a CNAME, gotta find its A"
print "\n"
query = self.adns.submit(answer[1], adns.rr.A)
active_queries[query] = dns
else:
resolved_hosts[dns] = None
print "THIS COULD NOT BE RESOLVED"
def finished_resolving():
print "inside finished_resolving()"
print "Resolved : " + str(len(resolved_hosts)) + "/" + str(len(self.dnslist))
return len(resolved_hosts) == len(self.dnslist)
while not finished_resolving():
print "Inside 'while not finished_resolving'"
while dns_queue and len(active_queries) <= self.intensity:
print "Queue: " + str(len(active_queries)) + "/" + str(self.intensity)
dns = dns_queue.pop()
self.adns = adns.init(adns.iflags.noautosys,sys.stderr,"nameserver "+dns)
query = self.adns.submit(host, record)
print "Launching Querying for " + host + "/" + str(record) + " on " + dns
active_queries[query] = dns
collect_results()
return resolved_hosts
最佳答案
我刚刚尝试使用 adns python 绑定(bind)并遇到了类似的问题 - 已完成的查询数组永远不会被完全填满,导致检查循环永远运行。在我的例子中,似乎无法解析的域(由于 NXDOMAIN 等)从未添加到已完成的查询数组(具有空/空值)
我查看了 C 绑定(bind),但看不到用于保存失败结果的单独数据结构,因此看起来确实应该以某种方式将这些添加到“已完成”查询中。我怀疑绑定(bind)或 adns 库中存在阻止这种情况发生的错误。
关于Python 和 ADNS,在某处陷入无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3853190/
我有 3 个列表项,每 3 秒向上旋转一次。我正在使用 transformY 属性来做这件事。问题是,当它到达最后一个元素时,它会循环返回,从而产生重新开始的效果。 如何通过在最后一项之后继续向上旋转
我如何制作一个处理旋转的无限/重复世界,就像在这个游戏中一样: http://bloodfromastone.co.uk/retaliation.html 我通过具有这样的层次结构对我的旋转移动世界进
这个问题已经有答案了: Using explicitly numbered repetition instead of question mark, star and plus (4 个回答) 已关闭
程序说明: I have this program of mine which is intended to read every word from a file (large one) and t
while 循环应该比较这两个对象的 ibsn。正在比较的对象: list[0] = new ReadingMatter ("Words and Stuff", "9-082-1090-1");
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我完全被屏蔽了。我尝试修改 C 中的“警报”信号,以便在秒数到期时读取一个简单的变量。我的代码如下: 在主要部分: int semnal; signal(SIGALRM, alarmHandle
我正在接受多行信息(字符串,直到我稍后解析它们)。例如: 1 5 0 2 9 6 2 9 1 我编写这段代码来分隔行,因为我将不得不以某种方式操作每一行。 Scanner scan = new Sca
我不熟悉 jQuery,并且我有多余的 jQuery 调用,我想将它们放入循环中。 $('.class1').on('click', function () { ... $('.class2').on
我有一个树结构,其中每个节点都有 5 个子节点,并且不允许超过 5 个。我希望以广度优先搜索的方式遍历这棵树。 现在我想使用广度优先搜索方式从选定的父节点计算空节点。 例如 如果给定的父节点为 1,则
目标/动机 我想写一个服务,它应该一直运行。但是当服务已经运行时,应该不可能再次启动该服务。 用例 用户 X 打开页面 myService.php 并通过单击页面上的按钮启动服务。之后关闭浏览器。一段
我正在尝试编译 shogun 工具箱,但遇到了这个错误 C:/shogun-3.0.0/shogun-3.0.0/src/shogun/../shogun/mathematics/Math.h
需要学校的 JavaScript 作业帮助,但不知道该怎么做,希望得到一些提示? 我们应该创建一个 6 面掷骰子程序,用户可以选择应该掷多少个骰子,最少 1 个和最多 5 个骰子。 所用骰子数量的总和
我在无限 ScrollView 中有 5 张图片。 因此,为了使 scrollView 无限/循环,我将图像定位如下: 5 1 2 3 4 5 1含义:最后一张图片第一张图片第二张图片.....最后一
我正在使用 ExTwitter库,并希望能够偶尔终止对流式 API 的调用以更改参数。 我当前的代码看起来像这样: for tweet #finished end 关于elixir - 如何中断(无
我想每 3 秒更改一次 div 的背景。这需要循环,因此一旦最后一个背景图像显示,它就会循环回到第一个背景图像,依此类推。我在这样做时遇到了麻烦。 我之前发过一篇文章,内容非常模糊,没有得到帮助。
我在做this教程,无法让我的页面正确加载。我不断在控制台中收到错误:[$rootScope:infdig]。 我对 Angular 很陌生,但从我读到的内容来看,我在某个地方有一个无限循环。我预计它
所以我试图创建一个无限的 asyncIterator/生成器。该代码应该为“for wait of”循环生成“Hello”和“Hi”,然后永远等待下一个值。问题是它不等待第三个值,也不在循环后打印 2
下图显示了我如何在 HTML5/JS 中制作无限背景滚动。我的连续背景由 X block Canvas 组成。我将在到达下一个 Canvas 之前立即渲染它,并释放上一个 Canvas。这里的问题是动
作为一个业余项目,我正在研究一些自制的素数生成问题,尝试编写一些不同的实现作为自学 C 和 C++ 的方法。当然,生成低素数的最快方法是已经拥有它们,所以我想着手建立一个硬盘素数列表数据文件。我想编写
我是一名优秀的程序员,十分优秀!