def database_server_ipc_path(): core_db = AtomicDB() core_db[b'key-a'] = b'value-a' chaindb = ChainDB(core_db) # TODO: use a custom chain class only for testing. chaindb.persist_header(ROPSTEN_GENESIS_HEADER) with tempfile.TemporaryDirectory() as temp_dir: trinity_config = TrinityConfig( network_id=ROPSTEN_NETWORK_ID, data_dir=temp_dir, ) manager = get_chaindb_manager(trinity_config, core_db) chaindb_server_process = multiprocessing.Process( target=serve_chaindb, args=(manager, ), ) chaindb_server_process.start() wait_for_ipc(trinity_config.database_ipc_path) try: yield trinity_config.database_ipc_path finally: kill_process_gracefully(chaindb_server_process, logging.getLogger())
def run_database_process(trinity_config: TrinityConfig, db_class: Type[BaseDB]) -> None: with trinity_config.process_id_file('database'): base_db = db_class(db_path=trinity_config.database_dir) manager = get_chaindb_manager(trinity_config, base_db) server = manager.get_server() # type: ignore def _sigint_handler(*args: Any) -> None: server.stop_event.set() signal.signal(signal.SIGINT, _sigint_handler) try: server.serve_forever() except SystemExit: server.stop_event.set() raise