def test_IPC_CREAT_new(self): """tests sysv_ipc.IPC_CREAT to create a new SharedMemory without IPC_EXCL""" # I can't pass None for the name unless I also pass IPC_EXCL. key = tests_base.make_key() # Note: this method of finding an unused key is vulnerable to a race # condition. It's good enough for test, but don't copy it for use in # production code! key_is_available = False while not key_is_available: try: mem = sysv_ipc.SharedMemory(key) mem.detach() mem.remove() except sysv_ipc.ExistentialError: key_is_available = True else: key = tests_base.make_key() mem = sysv_ipc.SharedMemory(key, sysv_ipc.IPC_CREAT, size=sysv_ipc.PAGE_SIZE) self.assertIsNotNone(mem) mem.detach() mem.remove()
def test_IPC_CREAT_new(self): """tests sysv_ipc.IPC_CREAT to create a new semaphore without IPC_EXCL""" # I can't pass None for the name unless I also pass IPC_EXCL. key = tests_base.make_key() # Note: this method of finding an unused key is vulnerable to a race # condition. It's good enough for test, but don't copy it for use in # production code! key_is_available = False while not key_is_available: try: sem = sysv_ipc.Semaphore(key) sem.close() except sysv_ipc.ExistentialError: key_is_available = True else: key = tests_base.make_key() sem = sysv_ipc.Semaphore(key, sysv_ipc.IPC_CREAT) self.assertIsNotNone(sem) sem.remove()