Skip to content

Commit 94fd26c

Browse files
committed
Fix exception when unpickling operator objects
Discovered when debugging a deadlock when evaluating a roll in a process pool executor. The use of the negate (-) operator was enough to trigger the bug. Pickle is used to de/serialize data when communicating with worker processes, but it was unable to reconstruct the operator object because of missing arguments to `__new__`. Overriding the `__getnewargs__` method to return the necessary arguments solved the problem, since the default is assumed to be an empty tuple. reprex: ```py r = dice.roll('-d20', raw=True) d = pickle.dumps(r) pickle.loads(d) ```
1 parent ab40709 commit 94fd26c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

dice/elements.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ def __repr__(self):
393393
classname(self), ", ".join(map(str, self.original_operands))
394394
)
395395

396+
def __getnewargs__(self):
397+
return self.original_operands
398+
396399
def preprocess_operands(self, *operands, **kwargs):
397400
def eval_wrapper(operand):
398401
return self.evaluate_object(operand, **kwargs)

0 commit comments

Comments
 (0)