def thread_play_random(queue, num=1000, qp=None): config.read_cfg('config-b10f2') go.set_board_size(config.board_size) game_num = 0 data = dataset.DataSet() name = mp.current_process().name config.running = True while config.running: train_start = time.time() board = strategies.simulate_game(board.Board(komi=7.5)) queue.put("{}--{:.0f}:第{}盘随机盘面已准备就绪,共{}步,开始复盘……".format( name, time.time() - train_start, game_num, board.step)) train_start = time.time() replay(board, data, queue, 100, qp) queue.put("{}--{:.0f}:第{}盘复盘完成。".format(name, time.time() - train_start, game_num)) game_num += 1 if game_num >= num: break if data.data_size > 256: queue.put(name + "--保存训练数据……") data.save() queue.put(name + "--保存完毕!")
def thread_play(queue, net=None, num=100, qp=None): config.read_cfg('config-b10f2') go.set_board_size(config.board_size) data = dataset.DataSet() name = mp.current_process().name for i in range(num): train_start = time.time() queue.put("{}--{:.0f}:开始下第{}盘棋……".format(name, time.time() - train_start, i + 1)) train_start = time.time() board = play(None, data, queue, net, qp, "sgf") queue.put("{}--{:.0f}:第{}盘棋下完。{}".format(name, time.time() - train_start, i + 1, go.result_str(board.result))) if data.data_size > 256: queue.put(name + "--保存训练数据……") data.save() queue.put(name + "--保存完毕!")
import os from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_mail_sendgrid import MailSendGrid import config cfg = config.read_cfg() # Create Flask application app = Flask(__name__) app.config.from_pyfile("flask_config.py") app.config.from_pyfile("flask_config_secret.py") if os.getenv("DEBUG"): app.config["DEBUG"] = True app.config["SQLALCHEMY_DATABASE_URI"] = cfg.db_filename if os.getenv("SESSION_KEY"): app.config["SECRET_KEY"] = os.getenv("SESSION_KEY") if os.getenv("PASSWORD_SALT"): app.config["SECURITY_PASSWORD_SALT"] = os.getenv("PASSWORD_SALT") if os.getenv("SENDGRID_API_KEY"): app.config["MAIL_SENDGRID_API_KEY"] = os.getenv("SENDGRID_API_KEY") if os.getenv("SERVER_NAME"): app.config["SERVER_NAME"] = os.getenv("SERVER_NAME") db = SQLAlchemy(app) mail = MailSendGrid(app)
def ws_worker(q, loop): try: loop.run_until_complete(ws_send(config.WS_ADDRESS, q)) except websockets.exceptions.ConnectionClosedError: print( 'Websocket client disconnected?!\nPlease check if the websocket server is running.' ) time.sleep(1) finally: ws_worker(q, loop) if __name__ == "__main__": config.read_cfg() while True: try: api.api_init() break except: if input( "Your DeFRaG engine is not running. Would you like us to launch it for you? [Y/n]: " ).lower() == "y": launch() time.sleep(2) logfile_path = config.DF_DIR + '\\qconsole.log' con_process = threading.Thread(target=console.read, args=(logfile_path, ),
def main(argv): """Control flow for reading the config settings and processing sounds. Get the configuration from the file :const:`CFG_FILE` (if it exists) and update the configuration from command-line args (if any). Extract internal resources for the duration of the remaining work; will be automatically cleaned up afterward. If no config, instantiate a default config and exit. Construct a :class:`config.Settings` object, and read the file table. Process the selected sounds, and then print any that were not found. :param argv: command-line arguments :type argv: iterable(str) :returns: 1 if an error prevents an attempt at processing or instantiation of the default config file; 0 otherwise :rtype: int :raises config.BadSetting: if a necessary setting is undefined :raises config.TooManySubstitutions: if a setting-evaluation loop goes on for too many iterations """ # Grab a couple of useful paths. qs_home = app_home() qs_working_dir = os.getcwd() # Read the config file (if it exists). cfg_path = os.path.join(qs_working_dir, CFG_FILE) cfg_table = config.read_cfg(cfg_path) # Apply any command-line args. config.update_cfg(argv, cfg_table) # Set pause_on_exit appropriately, and extract packaged resources for the # duration of the remaining work. path_table = {'qs_home' : add_sep(qs_home), 'qs_working_dir' : add_sep(qs_working_dir)} set_pause_on_exit(cfg_table, path_table) temp_dir = user_temp_dir(cfg_table, path_table) with resources.temp_copies(RES_PATH, temp_dir) as resource_dir: # Print info about this program and internal utilities. print_qs_info(resource_dir) # Do we have any config? If not, create a default config file and exit. if not cfg_table: print("No settings in config file or on command line.") if not create_config_file(cfg_path, resource_dir): return 1 print("Edit the config (if you like) then run quakesounds again.") return 0 # Create the settings-evaluator. path_table['qs_internal'] = add_sep(resource_dir) settings = config.Settings(cfg_table, path_table) # Set verbosity for the remainder of the run, and print module info # if verbose. set_verbosity(settings) print_modules_info() print("") # Get the sound selections and name mappings. targets_path = settings.eval('targets_path') targets_table = config.read_cfg(targets_path, default_sound_name) if not targets_table: if os.path.exists(targets_path): print("Nothing to process in the targets table at path: {0}".format( targets_path)) return 0 else: print("No targets table found at path: {0}".format(targets_path)) return 1 # Do that voodoo that we do. if not processing.go(settings, targets_table): return 1 # Inform of leftovers. if targets_table: print("Not processed:") for t in targets_table: print(" {0}".format(t)) else: print("All selections processed.") print("") # Done! return 0