示例#1
0
 def create(self, c, typeid, *args, **kwargs):
     # Unless set up as a shared proxy, don't make shared_memory_context
     # a standard part of kwargs.  This makes things easier for supplying
     # simple functions.
     if hasattr(self.registry[typeid][-1], "_shared_memory_proxy"):
         kwargs['shared_memory_context'] = self.shared_memory_context
     return Server.create(self, c, typeid, *args, **kwargs)
示例#2
0
 def create(*args, **kwargs):
     """Create a new distributed-shared object (not backed by a shared
     memory block) and return its id to be used in a Proxy Object."""
     # Unless set up as a shared proxy, don't make shared_memory_context
     # a standard part of kwargs.  This makes things easier for supplying
     # simple functions.
     if len(args) >= 3:
         typeod = args[2]
     elif 'typeid' in kwargs:
         typeid = kwargs['typeid']
     elif not args:
         raise TypeError("descriptor 'create' of 'SharedMemoryServer' "
                         "object needs an argument")
     else:
         raise TypeError('create expected at least 2 positional '
                         'arguments, got %d' % (len(args)-1))
     if hasattr(self.registry[typeid][-1], "_shared_memory_proxy"):
         kwargs['shared_memory_context'] = self.shared_memory_context
     return Server.create(*args, **kwargs)
示例#3
0
class SharedMemoryServer(Server):

    public = Server.public + \
             ['track_segment', 'release_segment', 'list_segments']

    def __init__(self, *args, **kwargs):
        Server.__init__(self, *args, **kwargs)
        address = self.address
        # The address of Linux abstract namespaces can be bytes
        if isinstance(address, bytes):
            address = os.fsdecode(address)
        self.shared_memory_context = \
            _SharedMemoryTracker(f"shm_{address}_{getpid()}")
        util.debug(f"SharedMemoryServer started by pid {getpid()}")

    def create(self, c, typeid, /, *args, **kwargs):
        """Create a new distributed-shared object (not backed by a shared
        memory block) and return its id to be used in a Proxy Object."""
        # Unless set up as a shared proxy, don't make shared_memory_context
        # a standard part of kwargs.  This makes things easier for supplying
        # simple functions.
        if hasattr(self.registry[typeid][-1], "_shared_memory_proxy"):
            kwargs['shared_memory_context'] = self.shared_memory_context
        return Server.create(self, c, typeid, *args, **kwargs)