3

我试图用一些更简单的功能重现它,但没有成功。所以下面的代码展示了我们的生产服务器抛出的很多 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 对象的字典

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

我问了我的 2 位同行和#python 上的人,但没有人能够猜到这是怎么发生的。

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

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

这是一个完整的跟踪。

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

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

4

1 回答 1

0

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

于 2012-05-09T14:49:17.920 回答