Pickle serializes Python data into bytes and reconstructs data from those bytes. It commonly carries objects between processes, but it does not transfer code. section 3.1.3
Account for these practical limits when choosing pickle for communication:
- Lambdas cannot be pickled with the default configuration, so a process pool cannot transfer them as-is; rewriting a lambda as a named function fixes the demonstrated case. section 3.4.1
- Foreign-library objects may need separate handling; file pointers, database connections, and sockets may be impossible to transfer or require extra care. section 3.4.1
- Serialization and interprocess communication can be slow enough to undermine multiprocessing when data volumes are large. section 3.4.1
Sending data over a socket
A synchronous client pickles its data, sends the byte length and payload over TCP, and uses a separate mechanism to transfer code. The example highlights that framing and compact, fast encoding may require handling outside pickle. section 3.1.3
<Future at 0x7f1ffff104c0 state=finished raised PicklingError> Can't pickle <function <lambda> at 0x7f2000131ca0>: attribute lookup <lambda> on __main__ failed
The failed future shows the pickling error raised when the process pool tries to transfer a lambda. section 3.4.1


