Intermittent KeyError raised and cannot play it

I tried to play it using some simpler functions, but failed. Thus, the following code shows the important methods for KeyError that are often generated by our production servers.

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()]
...

And here is the Traceback.

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 is a list with serial numbers
  • self.serial2player is a dict that maps series to Player objects.

Now it should not be possible for a KeyError to be raised in playersNotFold, because therefore the same error should have been raised in serialsNotFold, which it does not receive.

I asked my 2 peers and guys in #python, but no one could even figure out how this could happen.

If you need the full source: https://github.com/pokermania/poker-network/

EDIT: , traceback.format_exc (limit = 4), , . 2 , NotFold .

.

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

, :/

+3
1

, , self.serial2player .

0

All Articles