Beispiel #1
0
    def iter_queue(self):
        """Iterator fetching features from the queue

            Note that this iterator is lazy and multiprocess-affected:
            it cannot know its set of features in advance, will dynamically
            yield ones as found in the queue
        """
        while True:
            try:
                job_id = self.jobsq.get(timeout=0.5)
            except queue.Empty:
                break

            job = self.jobs_map.get(job_id, None)
            if job is None:
                print(("ERROR: missing job id=%s from map" % job_id))
                self.jobsq.task_done()
                continue

            if isinstance(job, Feature):
                yield job
                try:
                    self.resultsq.put((job_id, job.send_status()))
                except Exception as e:
                    print(("ERROR: cannot send result: {0}".format(e)))
            elif isinstance(job, Scenario):
                # construct a dummy feature, having only this scenario
                kwargs = {}
                for k in ('filename', 'line', 'keyword', 'name', 'tags',
                          'description', 'background', 'language'):
                    kwargs[k] = getattr(job.feature, k)
                kwargs['scenarios'] = [job]
                orig_parser = job.feature.parser
                feature = Feature(**kwargs)
                feature.parser = orig_parser
                yield feature
                try:
                    self.resultsq.put((job_id, job.send_status()))
                except Exception as e:
                    print(("ERROR: cannot send result: {0}".format(e)))
            else:
                raise TypeError("Don't know how to process: %s" % type(job))
            self.jobsq.task_done()