4 ms·
Threads inherit the process's interpreter (which is how they share the GIL). Contrast to multiprocessing, which spawns a new interpreter and communicates with i
by hythloday 14y ago
Threads inherit the process's interpreter (which is how they share the GIL). Contrast to multiprocessing, which spawns a new interpreter and communicates with it via a python IPC, such as multiprocessing.Queue, which shares the interface with queue.Queue or the slightly clumsy multiprocessing.Value class:
from multiprocessing import Process, Value
def f(n):
n.value = 3.1415927
num = Value('d', 0.0)
p = Process(target=f, args=(num))
p.start()
p.join()
print num.value # 3.1415927
- Luyt 14y agoAh, args should be a tuple: p = Process(target=f, args=(num,))