def create_ic_relations_to_db(num_workers, to_db=False):
"""
Creates intercity relations and stores them in the database if desired.
If storing is desired, a connection to the database must be possible.
Blocks until the producers and workers are done.
:param num_workers: The number of workers to use for computing the
relation scores. This is a read-only operation.
:param to_db: Defaults to false. If true, the relations are stored.
"""
if to_db and not db_utils.connected_to_db():
LOGGER.error('No database connection!')
return
w_factory = workers.Workers()
man = Manager()
queue = man.Queue()
producers = w_factory.run_compute_ic_rels_workers(num_workers, queue,
join=False)
consumers = w_factory.run_store_ic_rels_worker(queue, join=False,
to_db=to_db)
# Join all workers when done
_join_ic_rel_workers(w_factory, producers, consumers)
评论列表
文章目录