gpt4 book ai didi

python - 间歇性 KeyError 引发且无法重现

转载 作者:行者123 更新时间:2023-11-28 19:26:29 26 4
gpt4 key购买 nike

我尝试用一​​些更简单的函数重现它,但没有成功。所以下面的代码显示了我们的生产服务器抛出的 KeyError 的相关方法,很多。

class PokerGame:
...
def serialsNotFold(self):
return filter(lambda x: not self.serial2player[x].isFold(), self.player_list)

def playersNotFold(self):
return [self.serial2player[serial] for serial in self.serialsNotFold()]
...

这是回溯。

Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/pokernetwork/pokertable.py", line 945, in update
try: self.game.historyReduce()
File "/usr/lib/python2.6/dist-packages/pokerengine/pokergame.py", line 3949, in historyReduce
self.turn_history = PokerGame._historyReduce(self.turn_history,self.moneyMap())
File "/usr/lib/python2.6/dist-packages/pokerengine/pokergame.py", line 1323, in moneyMap
money = dict((player.serial,player.money) for player in self.playersNotFold())
File "/usr/lib/python2.6/dist-packages/pokerengine/pokergame.py", line 3753, in playersNotFold
return [self.serial2player[serial] for serial in self.serialsNotFold()]
KeyError: 21485L
  • self.player_list 是连续剧列表
  • self.serial2player 是一个将连续剧映射到 Player 对象的字典

现在应该不可能在 playersNotFold 中引发 KeyError,因为因此必须在 serialsNotFold 中引发相同的错误,但事实并非如此。

我问了我的 2 个同事和 #python 上的人,但没人能猜出这是怎么发生的。

如果您需要完整的来源:https://github.com/pokermania/poker-network/

编辑:问题是我们打印了 traceback.format_exc(limit=4) ,它从顶部而不是底部进行限制。最后 2 个调用是隐藏的,所以看起来 playersNotFold 引发了异常。

这是一个完整的轨迹。

Traceback (most recent call last): 
File "/usr/lib/python2.7/pokernetwork/pokertable.py", line 704, in update
try: self.game.historyReduce()
File "/usr/lib/python2.7/pokerengine/pokergame.py", line 3953, in historyReduce
self.turn_history = PokerGame._historyReduce(self.turn_history,self.moneyMap())
File "/usr/lib/python2.7/pokerengine/pokergame.py", line 1327, in moneyMap
money = dict((player.serial,player.money) for player in self.playersNotFold())
File "/usr/lib/python2.7/pokerengine/pokergame.py", line 3757, in playersNotFold
return self.serial2player[serial] for serial in self.serialsNotFold()]
File "/usr/lib/python2.7/pokerengine/pokergame.py", line 3754, in serialsNotFold
return filter(lambda x: not self.serial2player[x].isFold(] self.player_list)
File "/usr/lib/python2.7/pokerengine/pokergame.py", line 3754, in <lambda>
return filter(lambda x: not self.serial2player[x].isFold(] self.player_list)
KeyError: 1521

很抱歉浪费了你的时间:/

最佳答案

我猜你使用线程并且 self.serial2player 被不同的线程修改。

关于python - 间歇性 KeyError 引发且无法重现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10518333/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com