Beispiel #1
0
        def create_tables_for_node(n, workers = {}):
            if "parallel_setup" in self.kwargs and self.kwargs["parallel_setup"]:
                for c in n.children:
                    if not self.interrupted:
                        workers[c.id].result()
                if self.interrupted:
                    return
                db = DB.from_pool(self.pool)
                db.set_praefix(f"p{self.id}_")
            else:
                db = self.db

            # create all columns and insert null if values are not used in parent
            # this only works in the current version of manual inserts without procedure calls in worker
            db.create_table(f"td_node_{n.id}", [self.td_node_column_def(c) for c in n.vertices] + self.td_node_extra_columns(n))
            if self.candidate_store == "table":
                db.create_table(f"td_node_{n.id}_candidate", [self.td_node_column_def(c) for c in n.vertices] + self.td_node_extra_columns())
                candidate_view = self.candidates_select(n)
                candidate_view = db.replace_dynamic_tabs(candidate_view)
                db.create_view(f"td_node_{n.id}_candidate_v", candidate_view)
            ass_view = self.assignment_view(n)
            ass_view = db.replace_dynamic_tabs(ass_view)
            db.create_view(f"td_node_{n.id}_v", ass_view)
            if "parallel_setup" in self.kwargs and self.kwargs["parallel_setup"]:
                db.close()
Beispiel #2
0
 def __init__(self, name, pool, max_worker_threads=12,
         candidate_store="cte", limit_result_rows=None,
         randomize_rows=False, **kwargs):
     self.name = name
     self.pool = pool
     self.candidate_store = candidate_store
     self.limit_result_rows = limit_result_rows
     self.randomize_rows = randomize_rows
     self.max_worker_threads = max_worker_threads
     self.kwargs = kwargs
     self.type = type(self).__name__
     self.db = DB.from_pool(pool)
     self.interrupted = False
Beispiel #3
0
    def node_worker(self, node, workers):
        try:
            for c in node.children:
                if not self.interrupted:
                    logger.debug("Node %d waiting for %d", node.id,c.id)
                    workers[c.id].result()

            if self.interrupted:
                logger.info("Node %d interrupted", node.id)
                return node

            db = DB.from_pool(self.pool)
            db.set_praefix(f"p{self.id}_")
            logger.debug("Creating records for node %d", node.id)
            self.solve_node(node,db)
            db.close()
            if not self.interrupted:
                logger.debug("Node %d finished", node.id)
            return node
        except Exception:
            logger.exception("Error in worker thread")
            os.kill(os.getpid(), signal.SIGUSR1)