I'm trying to print a multiprocessing queue and I only get the memory address of the object. Can someone please tell me why the devs decided not to implement the functionality?
Asked
Active
Viewed 181 times
1 Answers
2
Were you expecting to see the elements? Doing that would require removing all elements from the queue due to how the inter-process communication works, and the results wouldn't necessarily be "what's in the queue right now" with other processes pushing and popping elements concurrently.

user2357112
- 260,549
- 28
- 431
- 505
-
Interesting! The documentation of [`__repr__`](https://docs.python.org/3/reference/datamodel.html#object.__repr__) states: ‘If at all possible, this should look like a valid Python expression that could be used to recreate an object *with the same value* (given an appropriate environment).’ I thought it was to recreate an object with the same **initial** value, so that it worked for any objects. But actually it is to recreate an object with the same **current** value, which constraints the signature of `__init__` to pass all the information so restricts the class of representable objects. – Géry Ogam Mar 31 '22 at 13:22
-
Since the state of an object is stored in its `__dict__` attribute, why doesn’t the generic `object.__repr__` return it (in addition to the object class and id) so that it can be used to restore the object (like [that](https://stackoverflow.com/a/44595303/2326961))? – Géry Ogam Mar 31 '22 at 15:12
-
@Maggyero: If you did `x = []; x.append(1)`, you'd want `repr(x)` to be `'[1]'`, not `'[]'`, right? Using the initial value wouldn't make any sense. Plus, it'd require recording every object's initial value. – user2357112 Mar 31 '22 at 19:35
-
@Maggyero: As for `__dict__`, plenty of objects don't have a `__dict__` or don't hold all of their state in it. – user2357112 Mar 31 '22 at 19:52
-
Yes, we want the *current* object’s state, not its *initial* state, so that `eval(repr(x)) == x`. It requires a custom `__eq__` for equality check instead of identity check (at least for unit tests). So a custom `__repr__` go hand in hand with a custom `__eq__`. But the main difficulty of `eval(repr(x)) == x` is that since `__repr__` returns a string representation of the class call, it requires the signature of `__init__` to provide the necessary parameters to restore the object’s state. – Géry Ogam Mar 31 '22 at 21:54