打印变量时推迟的未处理错误

时间:2018-12-04 06:43:58

标签: python-2.7 twisted

我正在尝试运行以下代码行:

    def __init__(self, players, loot):
    self.players = players
    self.state = MATCH_STATE_ACTIVE
    self.pendingShutdown = False
    self.shutdownTime = 0
    self.timer = LoopingCall(self.update(self))
    self.timer.start(0.07)
    self.match_id = 5
    self.playerloot = []
    self.boxloot = []
    self.loot = loot
    print("match [%d]" % self.match_id)

这是抛出一个

Unhandled error in deferred

我已经缩小了范围,并且我知道错误发生在以下事实:

print("match [%d]" % self.match_id)

当尝试打印任何变量时。仅在此文件中发生错误,因为其他.py文件可以打印变量。

1 个答案:

答案 0 :(得分:-1)

问题是由运行引起的

self.timer = LoopingCall(self.update(self))
self.timer.start(0.07)

为时过早,这两行必须放置在 init 的末尾,并且必须删除循环调用中的(自我),因此请替换为 LoopingCall(self.update)

def __init__(self, players, loot):
self.players = players
self.state = MATCH_STATE_ACTIVE
self.pendingShutdown = False
self.shutdownTime = 0
self.match_id = 5
self.playerloot = []
self.boxloot = []
self.loot = loot
print("match [%d]" % self.match_id)
self.timer = LoopingCall(self.update)
self.timer.start(0.07)