Python 2.7: Unexpected behavior with multiprocessing.Queue when using custom objects
I'm encountering unexpected behavior when trying to use `multiprocessing.Queue` to send custom objects between processes in Python 2.7. I have a class that represents a simple data structure, and I'm trying to pass instances of this class through the queue. Here's my class definition and how I'm using it: ```python import multiprocessing class CustomObject(object): def __init__(self, data): self.data = data def __str__(self): return 'CustomObject(data={})'.format(self.data) def worker(queue): while True: obj = queue.get() if obj is None: break print('Received:', obj) if __name__ == '__main__': q = multiprocessing.Queue() p = multiprocessing.Process(target=worker, args=(q,)) p.start() obj1 = CustomObject('test1') obj2 = CustomObject('test2') q.put(obj1) q.put(obj2) q.put(None) # Signal the worker to exit p.join() ``` When I run this code, I expect the worker process to print `Received: CustomObject(data=test1)` followed by `Received: CustomObject(data=test2)`. However, I only see `Received: CustomObject(data=test1)` in the output, and it seems like the second object is not being received at all. I've confirmed that both objects are indeed being put into the queue. I've tried adding `queue.close()` and `queue.join_thread()` after `put()` calls, but that didn't help either. Could this be an issue with how my custom object is being serialized or deserialized? Are there specific requirements for objects being passed through `multiprocessing.Queue` in Python 2.7? Any insights or solutions would be greatly appreciated! What am I doing wrong? I'm working on a mobile app that needs to handle this. I'd love to hear your thoughts on this.