[issue29167] Race condition in enum.py:_decompose()

Simon Percivall report at bugs.python.org
Sat Jan 7 13:39:54 EST 2017


Simon Percivall added the comment:

Run this a couple of times (it fails for me the first time, but it's a race, so YMMV):

```
import enum
from concurrent.futures import ThreadPoolExecutor


class MyEnum(enum.IntFlag):
    one = 1


with ThreadPoolExecutor() as executor:
    print(list(executor.map(MyEnum.one.__or__, range(1000))))
```

An easy fix would be:

```
diff --git a/Lib/enum.py b/Lib/enum.py
index e79b0382eb..eca56ec3a7 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -846,7 +846,7 @@ def _decompose(flag, value):
         # check for named flags and powers-of-two flags
         flags_to_check = [
                 (m, v)
-                for v, m in flag._value2member_map_.items()
+                for v, m in list(flag._value2member_map_.items())
                 if m.name is not None or _power_of_two(v)
                 ]
     members = []
```

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29167>
_______________________________________


More information about the Python-bugs-list mailing list