python multiprocessing in Jupyter on Windows: AttributeError: Can’t get attribute “abc”

I got multiprocessing to work from within a Jupyter notebook on Windows by saving my function in a separate .py file and including that file in my notebook. Example: f.py: def f(name, output): output.put(‘hello {0}’.format(name)) return Code in Jupyter notebook: from multiprocessing import Process, Queue #Having the function definition here results in #AttributeError: Can’t get … Read more

Multiprocessing Share Unserializable Objects Between Processes

Most of the time it’s not really desirable to pass the reference of an existing object to another process. Instead you create your class you want to share between processes: class MySharedClass: # stuff… Then you make a proxy manager like this: import multiprocessing.managers as m class MyManager(m.BaseManager): pass # Pass is really enough. Nothing … Read more

multiprocessing: How can I ʀᴇʟɪᴀʙʟʏ redirect stdout from a child process?

The solution you suggest is a good one: create your processes manually such that you have explicit access to their stdout/stderr file handles. You can then create a socket to communicate with the sub-process and use multiprocessing.connection over that socket (multiprocessing.Pipe creates the same type of connection object, so this should give you all the … Read more

Multiprocessing pool with an iterator

If I have to guess what’s primarily wrong with your code, I’d say it’s in passing your input_rows to your process function insert() – the way multiprocessing.Pool.apply_async() works is to unpack the arguments passed to it, so your insert() function actually retreives 100 arguments instead of one argument with a list of 100 elements. This … Read more

Using multiprocessing.Manager.list instead of a real list makes the calculation take ages

Linux uses copy-on-write when subprocesses are os.forked. To demonstrate: import multiprocessing as mp import numpy as np import logging import os logger = mp.log_to_stderr(logging.WARNING) def free_memory(): total = 0 with open(‘/proc/meminfo’, ‘r’) as f: for line in f: line = line.strip() if any(line.startswith(field) for field in (‘MemFree’, ‘Buffers’, ‘Cached’)): field, amount, unit = line.split() amount … Read more