为什么这个while循环“挂起”?

2024-09-30 18:14:32 发布

您现在位置:Python中文网/ 问答频道 /正文

在我正在编写的程序中有一个while循环。它从网站获取交易数据并生成响应。只要没有来自站点的事务,它就会运行,但是当它从站点获取结果时,它会响应,然后停止继续循环。感谢您的任何意见。在

while True:
    atran = getatran()
    ntid = getntid()
    if (ntid != otid and ntid != "-1"):
        otid = ntid
        tlidfile = open('last_transaction_id.txt', 'w')
        tlidfile.write(str(otid))
        tlidfile.close()
        for x in range(len(atran['transactions'])) :
            amount = atran['transactions'][x-1]['amount']
            currency = atran['transactions'][x-1]['currency']
            note = atran['transactions'][x-1]['note']
            if note[:14] == "Transfer from:":
                sender = note[15:]
                if (sender == "satoshi4free") or (sender == "rabbit") or (sender == "mehbot") or (currency != 17): pass
                else: flip(currency,amount,sender)
    print "New: " + str(ntid)
    print "Old: " + str(otid)
    sleep(1)

添加了“print”New:“print”和“print”Old:”语句作为故障排除措施。巧合的是,当ntid!=“-1”表示循环停止。但是,循环至少通过“print”Old:“”语句完成,我假设是“sleep”语句。在

我有一个类似的功能,获取消息并对其进行响应。它工作得很好。具体如下:

^{pr2}$

Tags: orif语句amountoldcurrencysendernote
1条回答
网友
1楼 · 发布于 2024-09-30 18:14:32

我想最好给你的问题起个标题:

Why does my while loop "hang"?

显然,您有一些挂起的东西,要推断出它是什么,您需要在每一行添加print(最简单),或者更困难(除非您有一个IDE可以帮助您):使用调试器逐步检查它,或者通过探查器运行它。在

我认为这尽可能直接地回答了这个问题,没有足够的信息为你提供更具体的推论。在

相关问题 更多 >