1 SUSPECT #1
import threading
lock = threading.Lock()
lock.acquire()
lock.acquire() # second time, same thread # (no error β but this BLOCKS forever; the demo is the bug)
# threading.Lock is NOT reentrant; use threading.RLock for that. 2 SUSPECT #2
import struct
b = struct.pack("i", 2**40)
print(b) Traceback (most recent call last):
File "lineup.py", line 2, in <module>
b = struct.pack("i", 2**40)
~~~~~~~~~~~^^^^^^^^^^^^^
struct.error: 'i' format requires -2147483648 <= number <= 2147483647 3 SUSPECT #3
import weakref
class Tree:
def __init__(self, val): self.val = val; self.children = []
root = Tree(1)
ref = weakref.ref(root)
root = None
print(ref()) # (no error β but the output is the lesson)
None 4 SUSPECT #4
import asyncio
async def coro():
await asyncio.sleep(0)
return 42
result = coro()
print(result) # (no error β but the printed value is NOT 42)
<coroutine object coro at 0x7f3e2b1d8e40>
sys:1: RuntimeWarning: coroutine 'coro' was never awaited 5 SUSPECT #5
import pickle
x = lambda: 1
pickle.dumps(x) Traceback (most recent call last):
File "lineup.py", line 4, in <module>
pickle.dumps(x)
~~~~~~~~~~~~^^^
File "pickle.py", line 245, in dumps
Pickler(file, protocol).dump(obj)
[Previous line repeated 996 more times]
RecursionError: maximum recursion depth exceeded