Multiprocessing.shared_memory - Shared Memory for Direct Access across…
페이지 정보
작성자 Colby 작성일 25-12-02 01:57 조회 8 댓글 0본문
This module supplies a category, SharedMemory, for the allocation and administration of shared memory to be accessed by one or more processes on a multicore or symmetric multiprocessor (SMP) machine. To assist with the life-cycle management of shared memory particularly across distinct processes, a BaseManager subclass, SharedMemoryManager, is also offered within the multiprocessing.managers module. In this module, shared memory refers to "POSIX style" shared memory blocks (though just isn't essentially implemented explicitly as such) and doesn't refer to "distributed shared memory". This fashion of shared memory permits distinct processes to potentially read and Memory Wave Program write to a typical (or shared) region of volatile memory. Processes are conventionally restricted to only have entry to their own process memory area but shared memory permits the sharing of information between processes, avoiding the necessity to as an alternative ship messages between processes containing that knowledge. Sharing knowledge immediately through memory can present significant efficiency benefits in comparison with sharing knowledge by way of disk or socket or other communications requiring the serialization/deserialization and copying of knowledge.
Create an occasion of the SharedMemory class for both creating a new shared memory block or attaching to an present shared memory block. Each shared memory block is assigned a novel identify. In this fashion, one process can create a shared memory block with a particular name and a distinct course of can attach to that very same shared memory block utilizing that same title. As a useful resource for sharing knowledge throughout processes, shared Memory Wave Program blocks might outlive the original process that created them. When one course of now not wants entry to a shared memory block that may still be needed by other processes, the close() technique ought to be known as. When a shared memory block is now not wanted by any process, the unlink() methodology needs to be referred to as to ensure correct cleanup. The distinctive title for the requested shared memory, specified as a string. When creating a brand new shared memory block, if None (the default) is provided for the identify, a novel title will likely be generated.
Control whether or not a brand new shared memory block is created (True) or an present shared memory block is connected (False). The requested number of bytes when creating a new shared memory block. As a result of some platforms select to allocate chunks of memory based upon that platform’s memory web page measurement, the exact size of the shared memory block may be larger or equal to the dimensions requested. When attaching to an current shared memory block, the scale parameter is ignored. When True, register the shared memory block with a resource tracker course of on platforms the place the OS doesn't do that routinely. The useful resource tracker ensures correct cleanup of the shared memory even if all other processes with access to the memory exit with out doing so. Python processes created from a standard ancestor using multiprocessing facilities share a single useful resource tracker process, and the lifetime of shared memory segments is handled automatically among these processes.
Python processes created in any other manner will receive their very own useful resource tracker when accessing shared memory with track enabled. This may trigger the shared memory to be deleted by the useful resource tracker of the first process that terminates. To avoid this concern, customers of subprocess or standalone Python processes should set monitor to False when there's already one other course of in place that does the bookkeeping. Home windows, which has its own monitoring and mechanically deletes shared memory when all handles to it have been closed. Modified in model 3.13: Added the observe parameter. Shut the file descriptor/handle to the shared memory from this instance. Relying on operating system, the underlying memory might or is probably not freed even if all handles to it have been closed. To ensure correct cleanup, use the unlink() methodology. Delete the underlying shared memory block. This needs to be called solely as soon as per shared memory block regardless of the variety of handles to it, even in different processes.
This methodology has no effect on Windows, the place the one solution to delete a shared memory block is to shut all handles. A memoryview of contents of the shared memory block. Learn-only entry to the distinctive title of the shared memory block. Read-solely entry to dimension in bytes of the shared memory block. A subclass of multiprocessing.managers.BaseManager which can be utilized for the management of shared memory blocks across processes. A call to start out() on a SharedMemoryManager occasion causes a brand new course of to be started. This new process’s sole objective is to handle the life cycle of all shared memory blocks created by means of it. To trigger the discharge of all shared memory blocks managed by that course of, call shutdown() on the occasion. This triggers a unlink() name on all of the SharedMemory objects managed by that course of after which stops the method itself. By creating SharedMemory instances by means of a SharedMemoryManager, we keep away from the necessity to manually monitor and set off the freeing of shared memory assets.
- 이전글 바다의 아름다움: 해변과 해양 생태계
- 다음글 Ten Awesome Tips About Highstakes 777 Online Login From Unlikely Sources
댓글목록 0
등록된 댓글이 없습니다.