Python: use a global list in a callback function
<p>This is my callback function and I set the rcv_buffer to be global</p>

<pre><code>def rx_callback(ok, payload):
    global n_rcvd, n_right, rcv_buffer
    n_rcvd += 1
    (pktno,) = struct.unpack('!H', payload[0:2])
    if ok:
        n_right += 1
        rcv_buffer.append((pktno, payload))
</code></pre>

<p>And in the main() I continuously check the buffer to see whether the buffer is empty:</p>

<pre><code>   while 1:
        while len(rcv_buffer) &gt; 0:
            (pktno, payload) = rcv_buffer.pop(0)
            print 'pktno = ', pktno, 'payload = ', payload[2:]
</code></pre>

<p>But I didn't do any synchronizations! Can I be sure that my operations on the list will not crash?Thanks!</p>
