def test_remove_semaphore(self):
        """Exercise remove_semaphore()"""
        sem = sysv_ipc.Semaphore(None, sysv_ipc.IPC_CREX)

        sysv_ipc.remove_semaphore(sem.id)

        with self.assertRaises(sysv_ipc.ExistentialError):
            sysv_ipc.Semaphore(sem.key)
Пример #2
0
    def Process(self):
        # I seed the shared memory with a random value which is the current time.
        what_i_wrote = time.asctime()
        s = what_i_wrote

        #utils.write_to_memory(self.Memory, what_i_wrote)

        utils.say("iteration %d" % self.Cntr)
        self.Cntr += 1

        if not self.Params["LIVE_DANGEROUSLY"]:
            # Releasing the semaphore...
            utils.say("releasing the semaphore")
            self.Semaphore.release()
            utils.say("acquiring the semaphore...")
            self.Semaphore.acquire()

        self.DispatchMsg(utils.read_from_memory(self.Memory))

        if self.State == "IDLE":
            pass
        elif self.State == "INCR":
            pass
        elif self.State == "DECR":
            pass
        elif self.State == "QUIT":
            if not self.Params["LIVE_DANGEROUSLY"]:
                utils.say(
                    "Final release of the semaphore followed by a 5 second pause"
                )
                self.Semaphore.release()
                time.sleep(5)
                # ...before beginning to wait until it is free again.
                utils.say("Final acquisition of the semaphore")
                self.Semaphore.acquire()

            utils.say("Destroying semaphore and shared memory")
            # It'd be more natural to call memory.remove() and semaphore.remove() here,
            # but I'll use the module-level functions instead to demonstrate their use.
            sysv_ipc.remove_shared_memory(self.Memory.id)
            sysv_ipc.remove_semaphore(self.Semaphore.id)
        else:
            sysv_ipc.remove_shared_memory(self.Memory.id)
            sysv_ipc.remove_semaphore(self.Semaphore.id)
 def unlink_static( sem ):
     """ 静态方法
     Params: Semaphore Object """
     sysv_ipc.remove_semaphore(sem.id)
Пример #4
0
    # What I read must be the md5 of what I wrote or something's gone wrong.
    what_i_wrote = what_i_wrote.encode()

    try:
        assert(s == hashlib.md5(what_i_wrote).hexdigest())
    except AssertionError:
        raise AssertionError("Shared memory corruption after %d iterations." % i)

    # MD5 the reply and write back to Mrs. Conclusion.
    s = s.encode()
    what_i_wrote = hashlib.md5(s).hexdigest()
    utils.write_to_memory(memory, what_i_wrote)


# Announce for one last time that the semaphore is free again so that
# Mrs. Conclusion can exit.
if not params["LIVE_DANGEROUSLY"]:
    utils.say("Final release of the semaphore followed by a 5 second pause")
    semaphore.release()
    time.sleep(5)
    # ...before beginning to wait until it is free again.
    utils.say("Final acquisition of the semaphore")
    semaphore.acquire()

utils.say("Destroying semaphore and shared memory")
# It'd be more natural to call memory.remove() and semaphore.remove() here,
# but I'll use the module-level functions instead to demonstrate their use.
sysv_ipc.remove_shared_memory(memory.id)
sysv_ipc.remove_semaphore(semaphore.id)
Пример #5
0
        what_i_wrote = what_i_wrote.encode()

    try:
        assert(s == hashlib.md5(what_i_wrote).hexdigest())
    except AssertionError:
        flex_utils.raise_error(AssertionError, 
                        "Shared memory corruption after %d iterations." % i)

    # MD5 the reply and write back to Mrs. Conclusion.
    if PY_MAJOR_VERSION > 2:
        s = s.encode()
    what_i_wrote = hashlib.md5(s).hexdigest()
    utils.write_to_memory(memory, what_i_wrote)


# Announce for one last time that the semaphore is free again so that 
# Mrs. Conclusion can exit.
if not params["LIVE_DANGEROUSLY"]:
    utils.say("Final release of the semaphore followed by a 5 second pause")
    semaphore.release()
    time.sleep(5)
    # ...before beginning to wait until it is free again.
    utils.say("Final acquisition of the semaphore")
    semaphore.acquire()

utils.say("Destroying semaphore and shared memory")
# It'd be more natural to call memory.remove() and semaphore.remove() here, 
# but I'll use the module-level functions instead to demonstrate their use.
sysv_ipc.remove_shared_memory(memory.id)
sysv_ipc.remove_semaphore(semaphore.id)
Пример #6
0
 def Cleanup(self):
     sysv_ipc.remove_shared_memory(self.Memory.id)
     sysv_ipc.remove_semaphore(self.Semaphore.id)