Esempio n. 1
0
 def __init__(self,
              output_queue: Queue,
              text_generator,
              line_generator,
              name=-1):
     super().__init__(daemon=True)
     self.text_generator = TextGenerator(text_generator)
     self.line_generator = LineGenerator(line_generator)
     self.output_queue = output_queue
     self.text_only = False
     self.name = "{}".format(name)
Esempio n. 2
0
class LineGeneratorProcess(Process):
    def __init__(self,
                 output_queue: Queue,
                 text_generator,
                 line_generator,
                 name=-1):
        super().__init__(daemon=True)
        self.text_generator = TextGenerator(text_generator)
        self.line_generator = LineGenerator(line_generator)
        self.output_queue = output_queue
        self.text_only = False
        self.name = "{}".format(name)

    def _handle(self):
        try:
            words = self.text_generator.generate()
            image = self.line_generator.draw(
                words) if not self.text_only else None
            self.output_queue.put(
                (image, TextGenerator.words_to_unformatted_text(words)))
        except ValueError as e:
            print("Exception during line generation:", e)

    def run(self):
        random.seed()
        np.random.seed()
        try:
            while True:
                self._handle()
        except (EOFError, BrokenPipeError, ConnectionResetError):
            # queue closed, stop the process
            return
Esempio n. 3
0
 def _handle(self):
     try:
         words = self.text_generator.generate()
         image = self.line_generator.draw(
             words) if not self.text_only else None
         self.output_queue.put(
             (image, TextGenerator.words_to_unformatted_text(words)))
     except ValueError as e:
         print("Exception during line generation:", e)
Esempio n. 4
0
 def _handle(self):
     try:
         words = self.text_generator.generate()
         image = self.line_generator.draw(
             words) if not self.text_only else None
         self.output_queue.put(
             (image, TextGenerator.words_to_unformatted_text(words)),
             block=True,
             timeout=1)
     except ValueError as e:
         print(e)
     except Full as e:
         # Full queue
         return