Esempio n. 1
0
def t01():
    pretty = '%s t01' % __file__
    print(pretty)

    p = Pipe()
    p.put('hello')

    try:
        msg = p.get(timeout=0)
    except Exception, e:
        print('FAIL %s: first get() failed: %s' % (pretty, e))
        return False
Esempio n. 2
0
    def start(self, daemonize=False, synchronize=False):
        if synchronize:
            # pass a pipe down to the (grand) child so it can pass its pid back
            # when the child has been fully initialized. this synchronizes the
            # setup of signal handlers, which is otherwise hard to do for the
            # caller. it also lets the caller see the pid of daemon processes
            # as a property on the Process instance.
            # synchronization has a significant performance cost. disable it
            # for short lived daemons that need to be created quickly and will
            # not be interacted with by the caller. e.g. panotti shouters.
            pipe = Pipe()
            exclude = [pipe.w]
        else:
            pipe = None
            exclude = []
        if daemonize:
            if not self._daemonize():
                if synchronize:
                    self._pid = pipe.get()  # now guaranteed to be reparented
                    del pipe
                return  # parent returns to caller
            else:
                pass  # continue below, at self.redirect()
        else:
            self._pid = os.fork()
            if self._pid != 0:  # parent process
                if synchronize:
                    pipe.get()  # now guaranteed to be fully initialized
                    del pipe
                return
        self.close_fds(exclude)
        self.redirect()
        gc.collect()
        self.log('start PID=%d' % self.pid)
        self.initialize()

        if synchronize:
            pipe.put(self.pid)
            del pipe

        exit_code = 0

        try:
            self.target(*self.args)
        except Exception, e:
            self.log('Exception in target():\n%s' % traceback.format_exc())
            exit_code = 1
Esempio n. 3
0
            q2.get() # block until parent signals, then die

    q1 = Pipe()
    q2 = Pipe()
    p = Client(args=(q1, q2, r.address, factory.HOME.path))
    p.start()

    profiles = [profile_factory(prof) for prof in q1.get()]
    # check that the resources really are allocated
    listing = r.list_allocations_all()
    for resource in profiles:
        if resource not in listing:
            print('FAIL %s: resource not allocated: %s' % (pretty, resource))
            return False

    q2.put('DIE DIE DIE!')
    p.join() # wait for death

    # check that the resources are freed. no message is sent out when resources
    # are freed, so we'll just have to wait a little and hope the situation has
    # been handled by the time we look up allocations.
    time.sleep(1)
    listing = r.list_allocations_all()
    for resource in profiles:
        if resource in listing:
            print('FAIL %s: resource not freed: %s' % (pretty, resource))
            return False

    # double check that the handset is available again
    listing = r.list_handsets()
    if profiles[1] not in listing: