我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用mmap.ACCESS_WRITE。
def _initialize_shared_memory(self): """ This is the IPC channel between us (Python) and the PinTool (C/C++) """ s_uint32 = self.utils.get_size_uint32() shm_name = "Local\\NaFlSharedMemory" self.shm_size = self.bitmap_size * s_uint32 # architecture dependent :) self.shm = mmap.mmap(0, self.shm_size, shm_name, access = mmap.ACCESS_WRITE) if not self.shm: # Oops! self.ml.info('[!] Could not create the shared memory region') self.ml.info('[!] Aborting...') sys.exit(1)
def create(self, access='write'): """ Create a new block of shared memory using the mmap module. """ if access == 'write': mmap_access = mmap.ACCESS_WRITE else: mmap_access = mmap.ACCESS_READ name = "conque_%s_%s" % (self.mem_type, self.mem_key) self.shm = mmap.mmap(0, self.mem_size * self.char_width, name, mmap_access) if not self.shm: return False else: return True
def __init__(self, simulate_noise=True): self._random = Random() self._fd = init_humidity() self._map = mmap.mmap(self._fd.fileno(), 0, access=mmap.ACCESS_WRITE) data = self._read() if data.type != 2: self._write(HumidityData(2, b'HTS221', 0, 100, 0, 100, 0, 25600, 0, 6400, 0, 0, 0, 0)) self._humidity = 45.0 self._temperature = 20.0 else: self._humidity = data.H_OUT / HUMIDITY_FACTOR self._temperature = data.T_OUT / TEMP_FACTOR self._noise_thread = None self._noise_event = Event() self._noise_write() # The queue lengths are selected to accurately represent the response # time of the sensors self._humidities = np.full((10,), self._humidity, dtype=np.float) self._temperatures = np.full((31,), self._temperature, dtype=np.float) self.simulate_noise = simulate_noise
def __init__(self, simulate_noise=True): self._random = Random() self._fd = init_pressure() self._map = mmap.mmap(self._fd.fileno(), 0, access=mmap.ACCESS_WRITE) data = self._read() if data.type != 3: self._write(PressureData(3, b'LPS25H', 0, 0, 0, 0, 0)) self._pressure = 1013.0 self._temperature = 20.0 else: self._pressure = data.P_OUT / 4096 self._temperature = data.T_OUT / 480 + 42.5 self._noise_thread = None self._noise_event = Event() self._noise_write() # The queue lengths are selected to accurately represent the response # time of the sensors self._pressures = np.full((25,), self._pressure, dtype=np.float) self._temperatures = np.full((25,), self._temperature, dtype=np.float) self.simulate_noise = simulate_noise
def __init__(self, tagName='trader_msg', size = 1024*1024): self.fm = mmap.mmap(-1, size, access=mmap.ACCESS_WRITE, tagname=tagName) self.eventAu = win32event.OpenEvent(win32event.EVENT_ALL_ACCESS, 0 ,"aauto_trigger") self.eventPy = win32event.OpenEvent(win32event.EVENT_ALL_ACCESS, 0 ,"python_trigger") self.timeOut = 0xFFFFFFFF #???? win32event.ResetEvent(self.eventAu) win32event.ResetEvent(self.eventPy)
def __init__(self, simulate_world=True): self._random = Random() self._fd = init_imu() self._map = mmap.mmap(self._fd.fileno(), 0, access=mmap.ACCESS_WRITE) data = self._read() self._gravity = Z self._north = 0.33 * X if data.type != 6: self._write(IMUData(6, b'LSM9DS1', timestamp(), O, O, O, O)) self._accel = O self._gyro = O self._compass = O self._orientation = O self._position = O else: self._accel = data.accel / ACCEL_FACTOR self._gyro = data.gyro / GYRO_FACTOR self._compass = data.compass / COMPASS_FACTOR self._orientation = O # XXX calc orientation from accel and gravity self._position = O # XXX calc position from compass and north self._world_thread = None self._world_event = Event() self._world_write(timestamp()) # These queue lengths were arbitrarily selected to smooth the action of # the orientation sliders in the GUI; they bear no particular relation # to the hardware self._gyros = np.full((10, 3), self._gyro, dtype=np.float) self._accels = np.full((10, 3), self._accel, dtype=np.float) self._comps = np.full((10, 3), self._compass, dtype=np.float) self.simulate_world = simulate_world