4

When writing a program using multiprocessing and classes I sometimes stumble upon the exception

TypeError: cannot serialize '_io.TextIOWrapper' object

(the object can be different).

I understand why this is so and there are specific examples on how to fix specific cases.

Is there a straightforward way to tell which variable is causing the issue? This is not (at least for me) visible in the stack

Traceback (most recent call last):
  File "C:/Users/yop/dev/checkssllabs/checkssllabs.py", line 62, in <module>
    pool.map(s.analyse, sites)
  File "C:\Python34\lib\multiprocessing\pool.py", line 260, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "C:\Python34\lib\multiprocessing\pool.py", line 599, in get
    raise self._value
  File "C:\Python34\lib\multiprocessing\pool.py", line 383, in _handle_tasks
    put(task)
  File "C:\Python34\lib\multiprocessing\connection.py", line 206, in send
    self._send_bytes(ForkingPickler.dumps(obj))
  File "C:\Python34\lib\multiprocessing\reduction.py", line 50, in dumps
    cls(buf, protocol).dump(obj)
TypeError: cannot serialize '_io.TextIOWrapper' object

I will not be useful to post the (small) wall of code which generated this because I am looking for a generic way to hunt down these variables. Is the only way to analyze all of the imported modules and your own code, asking for every variable the question "is it serializable"?

To be totally frank I found, by miracle, the variable which was causing my specific problem but a generic approach would be very useful

Community
  • 1
  • 1
WoJ
  • 27,165
  • 48
  • 180
  • 345
  • It does not precisely answer your question, but you definitely should check out this thread: http://stackoverflow.com/questions/1816958/cant-pickle-type-instancemethod-when-using-pythons-multiprocessing-pool-ma The solutions presented there for me solved most problems concerning multiprocessing. – HeinzKurt Sep 10 '15 at 16:39
  • See the `dill` module for pickle debugging methods, including a pickle `trace` that recurses through a pickle call and prints the current object being serialized in the pickle stack. – Mike McKerns Sep 15 '15 at 00:46

0 Answers0