Teks sumber — English
Terjemahan — Bahasa Indonesia
*spawn* is now the default start method when there is no writable temporary directory, for example on a read-only file system. Previously *forkserver* remained the default there and starting a process failed with an :exc:`OSError`. The default is determined when it is first needed rather than when :mod:`!multiprocessing` is imported. See :gh:`155717`.
To select a start method you use the :func:`set_start_method` in the ``if __name__ == '__main__'`` clause of the main module. For example::
The :class:`Queue` class is a near clone of :class:`queue.Queue`. For example::
The :func:`Pipe` function returns a pair of connection objects connected by a pipe which by default is duplex (two-way). For example::
Data can be stored in a shared memory map using :class:`Value` or :class:`Array`. For example, the following code ::
A manager returned by :func:`Manager` will support types :class:`list`, :class:`dict`, :class:`set`, :class:`~managers.Namespace`, :class:`Lock`, :class:`RLock`, :class:`Semaphore`, :class:`BoundedSemaphore`, :class:`Condition`, :class:`Event`, :class:`Barrier`, :class:`Queue`, :class:`Value` and :class:`Array`. For example, ::
For example::
Sebagai contoh::
Functionality within this package requires that the ``__main__`` module be importable by the children. This is covered in :ref:`multiprocessing-programming` however it is worth pointing out here. This means that some examples, such as the :class:`multiprocessing.pool.Pool` examples will not work in the interactive interpreter. For example::
A queue must not be used anymore after it is closed. For example, :meth:`~Queue.get`, :meth:`~Queue.put` and :meth:`~Queue.empty` methods must no longer be called.
A queue must not be used anymore after it is closed. For example, :meth:`get`, :meth:`put` and :meth:`empty` methods must no longer be called.
One needs to call this function straight after the ``if __name__ == '__main__'`` line of the main module. For example::
For example:
Sebagai contoh:
Shared objects are capable of being nested. For example, a shared container object such as a shared list can contain other shared objects which will all be managed and synchronized by the :class:`SyncManager`.
To create one's own manager, one creates a subclass of :class:`BaseManager` and uses the :meth:`~BaseManager.register` classmethod to register new types or callables with the manager class. For example::
This authentication protects :class:`Listener` and :func:`Client` connections, which are reachable by address. It is not applied to the anonymous pipes created by :func:`~multiprocessing.Pipe` or used internally by :class:`~multiprocessing.Queue`. :mod:`multiprocessing` treats all local processes running as the same user as trusted; on most operating systems such processes can access each other's pipe file descriptors regardless. Applications that require isolation between processes of the same user must arrange it at the operating-system level -- for example, by running workers under a different user account or in a sandbox.
If you write a file-like object and implement your own caching, you can make it fork-safe by storing the pid whenever you append to the cache, and discarding the cache when the pid changes. For example::
For example, using the *spawn* or *forkserver* start method running the following module would fail with a :exc:`RuntimeError`::