On this page
multiprocessing.Value
Prev: multiprocessing.TimeoutError | Up: multiprocessing
Rel: multiprocessing.active_children, multiprocessing.allow_connection_pickling, multiprocessing.Array, multiprocessing.AuthenticationError
Ref: docs.python.org — multiprocessing.Value
Tags: #public #python3 #stdlib #multiprocessing
Import
import multiprocessing
from multiprocessing import Value
Signature & Overview
multiprocessing.Value(typecode_or_type, *args, lock=True)
Returns a synchronized shared object
Usage
import multiprocessing as mp
counter = mp.Value("i", 0)
with counter.get_lock():
counter.value += 1
assert counter.value == 1
Gotchas
counter.value += 1is NOT atomic withoutwith counter.get_lock():: Reading, incrementing, and writing are three separate operations.
REPL Inspect
from multiprocessing import Value
help(Value)
Linked from
Related notes
- tuts/python3/stdlib_module/multiprocessing/TimeoutError Linked here; links to this page; shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/multiprocessing/active_children Linked here; shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/allow_connection_pickling Linked here; shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/Array Linked here; shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/AuthenticationError Linked here; shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/Barrier shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/BoundedSemaphore shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/BufferTooShort shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/Condition shared tags: #multiprocessing, #stdlib