Intermittent KeyError raised and can not reproduce it
<p>I tried to reproduce it with some simpler functions but didn't succeed. So the following code shows the relevant methods for a KeyError which get's thrown by our production servers, a lot. </p>

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

<p>And here is the Traceback.</p>

<pre><code>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
</code></pre>

<ul>
<li>self.player_list is a list with serials</li>
<li>self.serial2player is a dict which maps serials to Player objects</li>
</ul>

<p>Now it shouldn't be possible that the KeyError is raised in playersNotFold because therefore the same error had to be raised in serialsNotFold, which it gets not.</p>

<p>I asked my 2 peers and the guys on #python but no one was able to even gues how this can happen.</p>

<p>If you need the full source: <a href="https://github.com/pokermania/poker-network/" rel="nofollow">https://github.com/pokermania/poker-network/</a></p>

<p><strong>EDIT:</strong>
The Problem was that we printed traceback.format_exc(limit=4) which limits from the top instead of the bottom. The last 2 calls where hidden, so it looked like playersNotFold raised the exception.</p>

<p>Here is a full trace.</p>

<pre><code>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 &lt;lambda&gt; 
    return filter(lambda x: not self.serial2player[x].isFold(] self.player_list) 
KeyError: 1521
</code></pre>

<p>I'm sorry for wasting your time :/</p>
