예제 #1
0
        def run(self):
            lock = koWndWrapper.create_mutex(self._commandmentsLockName)
            # existing: are there commandments from the invoking command-line?
            existing = os.path.exists(self._commandmentsFileName)
            newCommandments = koWndWrapper.create_event(
                self._commandmentsEventName, None, 1, existing)

            while 1:
                # Wait for new commandments.
                rv = koWndWrapper.wait_for_single_object(newCommandments)
                if rv == koWndWrapper.WAIT_OBJECT_0:
                    retval = 1
                else:
                    raise CommandmentError("Error waiting for new "
                                           "commandments: %r" % rv)
                # Grab the lock.
                koWndWrapper.wait_for_single_object(lock)
                # Consume the commandments.
                f = open(self._commandmentsFileName, 'r')
                cmds = []
                for line in f.readlines():
                    if line[-1] == '\n':
                        line = line[:-1]
                    if line.strip():  # skip empty lines
                        cmds.append(line)
                f.close()
                os.unlink(self._commandmentsFileName)
                # Reset the "new commandments" event.
                koWndWrapper.reset_event(newCommandments)
                # Release the lock.
                koWndWrapper.release_mutex(lock)

                # Handle the commandments.
                exit = 0
                for cmd in cmds:
                    if cmd == "__exit__":
                        exit = 1
                        break
                    else:
                        try:
                            _handleCommandment(cmd)
                        except Exception, ex:
                            tb = ''.join(
                                traceback.format_exception(*sys.exc_info()))
                            log.error("'%s': %s:\n%s", cmd, str(ex), tb)
                            #XXX Dialog proxy's alert() is screwed up.
                            #    It misbehaves and leads to Jaguar
                            #    crash.
                            #dialogProxy = components\
                            #    .classes["@activestate.com/asDialogProxy;1"]\
                            #    .getService(components.interfaces.asIDialogProxy)
                            #msg = "Error handling commandment: '%s'\n\n%s"\
                            #      % (cmd, tb)
                            #dialogProxy.alert(msg)
                if exit:
                    break
        def run(self):
            lock = koWndWrapper.create_mutex(self._commandmentsLockName)
            # existing: are there commandments from the invoking command-line?
            existing = os.path.exists(self._commandmentsFileName)
            newCommandments = koWndWrapper.create_event(self._commandmentsEventName, None, 1, existing)

            while 1:
                # Wait for new commandments.
                rv = koWndWrapper.wait_for_single_object(newCommandments)
                if rv == koWndWrapper.WAIT_OBJECT_0:
                    retval = 1
                else:
                    raise CommandmentError("Error waiting for new "
                                           "commandments: %r" % rv)
                # Grab the lock.
                koWndWrapper.wait_for_single_object(lock)
                # Consume the commandments.
                f = open(self._commandmentsFileName, 'r')
                cmds = []
                for line in f.readlines():
                    if line[-1] == '\n':
                        line = line[:-1]
                    if line.strip(): # skip empty lines
                        cmds.append(line)
                f.close()
                os.unlink(self._commandmentsFileName)
                # Reset the "new commandments" event.
                koWndWrapper.reset_event(newCommandments)
                # Release the lock.
                koWndWrapper.release_mutex(lock)

                # Handle the commandments.
                exit = 0
                for cmd in cmds:
                    if cmd == "__exit__":
                        exit = 1
                        break
                    else:
                        try:
                            _handleCommandment(cmd)
                        except Exception, ex:
                            tb = ''.join(traceback.format_exception(
                                *sys.exc_info()))
                            log.error("'%s': %s:\n%s", cmd, str(ex), tb)
                            #XXX Dialog proxy's alert() is screwed up.
                            #    It misbehaves and leads to Jaguar
                            #    crash.
                            #dialogProxy = components\
                            #    .classes["@activestate.com/asDialogProxy;1"]\
                            #    .getService(components.interfaces.asIDialogProxy)
                            #msg = "Error handling commandment: '%s'\n\n%s"\
                            #      % (cmd, tb)
                            #dialogProxy.alert(msg)
                if exit:
                    break
        def exit(self):
            # Grab the lock.
            lock = koWndWrapper.create_mutex(self._commandmentsLockName)
            koWndWrapper.wait_for_single_object(lock)
            # Send __exit__ commandment.
            f = open(self._commandmentsFileName, 'a')
            f.write("__exit__\n")
            f.close()
            # Signal that there are new commandments: to ensure worker
            # thread doesn't wedge.
            newCommandments = koWndWrapper.create_event(self._commandmentsEventName)
            koWndWrapper.set_event(newCommandments)
            koWndWrapper.close_handle(newCommandments)
            # Release the lock.
            koWndWrapper.release_mutex(lock)
            koWndWrapper.close_handle(lock)

            self.join()
            try:
                os.remove(self._commandmentsFileName)
            except EnvironmentError:
                pass
        def exit(self):
            # Grab the lock.
            lock = koWndWrapper.create_mutex(self._commandmentsLockName)
            koWndWrapper.wait_for_single_object(lock)
            # Send __exit__ commandment.
            f = open(self._commandmentsFileName, 'a')
            f.write("__exit__\n")
            f.close()
            # Signal that there are new commandments: to ensure worker
            # thread doesn't wedge.
            newCommandments = koWndWrapper.create_event(self._commandmentsEventName)
            koWndWrapper.set_event(newCommandments)
            koWndWrapper.close_handle(newCommandments)
            # Release the lock.
            koWndWrapper.release_mutex(lock)
            koWndWrapper.close_handle(lock)

            self.join()
            try:
                os.remove(self._commandmentsFileName)
            except EnvironmentError:
                pass