def shuffle(self): print("Shuffling the Deck ", end="") for _ in range(5): t_sleep(0.5) print(".", end="") random.shuffle(self.cards) print("\n")
def log_in(): while True: print( "----------------------------------------------------------------------------------" ) print("【國立臺灣大學管理學院生涯發展中心(CARDO)資料處理及資料庫管理程式】") print_licence() print("# 歡迎使用本資料庫系統") account = input("# 請輸入使用者帳號,或輸入'exit'離開本程式: ") if account == "exit": print("# 謝謝您的使用,歡迎下次光臨。") t_sleep(1) sys_exit(0) # terminate program if input exit else: # enter password password = input("# 請輸入使用者密碼: ") try: config = get_config(account, password) # 身分驗證 print('# 登入中....') database_management.pymysql_connect(**config) print("# 登入成功,歡迎回來", account, '\n\n') t_sleep(1) break except pymysql.err.OperationalError: print("# 您輸入的帳號或密碼錯誤,請再輸入一次。\n\n") return config
def sleep(stime, fractionCPU=0.5): # elapsed time to sleep, with fraction to be CPU stop = process_time() i = 1 while process_time() < stop + fractionCPU * stime: y = 10.0**i i = 1 if i > 10 else i + 1 t_sleep((1.0 - fractionCPU) * stime)
def enter_standby(): logger.debug('enter standby') display_device.contrast(CONST.BRIGHTNESS_STANDBY) _remove_powered_viewport() _setup_state_standby() t_sleep(1) virtual.refresh()
def run_game(): not_quit = True p1_turn = False # This will make sense below for who goes first p1_x = game.start_game() while not_quit: # Clear the display clear_display() # Initialize the game game_board = board.init_board() status = game.get_status(game_board, game.get_marker(p1_turn, p1_x)) # Take turns until game is won or lost or quit while status == "ongoing": # Change whose turn it is p1_turn = not p1_turn # Set current marker marker = game.get_marker(p1_turn, p1_x) # Get choice positions and valid positions and move print("\n----------------") print("\nOpen Options Board:") move_choice = game.move(*board.get_open_pos(game_board), p1_turn) # Update the board game_board = board.update_game_board(game_board, move_choice, marker) # Clear the display clear_display() # Display the Board print("\nGame Board:") board.display_board(game_board) # Check if game is won or stalemate status = game.get_status(game_board, marker) if status != "ongoing": break t_sleep(1) # See if they want to play again not_quit = game.set_replay(status, p1_turn) print("\nSorry to see you go, but I'll enjoy watching you walk away :)")
def display_loop(): while True: now = time.time() latestItem = toDisplay[-1] if latestItem['timeout'] < now: toDisplay.pop() continue # render text # print('would print at', latestItem['x'], latestItem['y'], latestItem['text']) with canvas(virtual) as draw: draw.text((-latestItem['x'], latestItem['y']), latestItem['text'], fill='white', font=latestItem['font']) # recalc position for next step if latestItem['x'] == latestItem['extra_size']: # reached end t_sleep(0.7) latestItem['x'] = 0 elif 0 != latestItem['extra_size']: if 0 == latestItem['x']: t_sleep(0.7) else: t_sleep(1 / 30) latestItem['x'] += 1 elif 0 == latestItem['x']: t_sleep(0.5)
def sleep_and_clear(sleep_s): """ sleep for X seconds and then clear the display. for use with jupyter notebooks Parameters ---------- sleep_s : int, float seconds to sleep for before clearing display Returns ------- None """ t_sleep(sleep_s) clear_display()
def run(self): print(self.name + " started.") while not self.urlsQueue.empty(): try: print("requesting...") # --T t_sleep(0.5) # --T content = ThreadDownloader.download(self, self.urlsQueue.get(False)) print(self.name + " putting content into dataQueue") self.dataQueue.put(content) except: pass print(self.name + "ended.")
def initalize(): # 1 PowerState.Powered / 0 PowerState.Standby global viewport_thread t_sleep(0.5) logger.debug('intialize radio display to state {}'.format( STATE['power_state'])) if STATE['power_state'] is PowerState.Powered: _setup_state_powered() elif STATE['power_state'] is PowerState.Standby: _setup_state_standby() elif STATE['power_state'] is PowerState.Unknown: logger.debug('POWER STATE NOT SET') _restart_viewport_thread()
def start_game(): """ Initialize the game Returns ------- p1_x: bool Whether p1's marker is X (true) or O (false) """ print("Welcome to Tic Tac Doh!\n") t_sleep(1) # Get Player 1 marker marker = input("Player 1: Enter Marker Choice X or O: ") while not(marker == "X" or marker == "O"): print("\nNow now Player 1, that was not a valid choice!\n") t_sleep(1) marker = input("\tPlayer 1: Enter Marker Choice X or O: ") return True if marker == "X" else False
def main(): from time import sleep as t_sleep # Single bar for j in range(20): bar = TextStatusBar(j) for i in range(j): t_sleep(0.1) bar.show(indentation="| |") print() # Double bars a, b = 10, 20 bar1 = TextStatusBar(a) bar2 = TextStatusBar(b) for i in range(a): bar1.hide() for j in range(b): t_sleep(0.5) bar2.show(indentation=bar1.refresh()) bar2.clear()
def admin_control(): print("【管理員模式】") print("0. 產生主表(請使用專用表格)") command = input("# 請輸入您所需要的功能,或輸入'exit'返回主選單: ") if command == 'exit': print("# 返回主選單") t_sleep(1) elif command == "0": # "C:\Users\ricardo\Desktop\Data\0311_藍天百腦匯報名清單(登陸出席).csv" while True: account = input("# 請輸入帳號: ") password = input("# 請輸入密碼: ") try: config = conf.get_config(account, password) # 身分驗證 print('# 登入中....') conn = database_management.pymysql_connect(**config) print("# 登入成功,歡迎回來", account, '\n\n') t_sleep(1) break except pymysql.err.OperationalError: print("# 您輸入的帳號或密碼錯誤,請再輸入一次。\n\n") # 12. 【活動結束後資料建檔】「已登記出席統計表」生成「計算完成統計表」並「輸入資料庫」" # "C:\Users\ricardo\Desktop\Data\0311_藍天百腦匯報名清單(登陸出席).csv" # Produce csv file after processing path, sem, semester_first, semester_second, fc, sc, date = view_CLI.get_information( "10") file_source = file_management.File(path, sem, semester_first, semester_second, fc, sc, date) file_source.get_file() data_source = data_processing.Data(file_source.year, file_source.semester, file_source.file_path, file_source.first_cat, file_source.second_cat) data, produced_df_path = data_source.data_processing() file_management.remove_temp() print('# 成功生成CSV') print('# 開始將生成csv輸入資料庫...') # set name of the table db_connection = database_management.DataConnection( data, config, fc, sc, date) # create new table for the data db_connection.create_table("主資料表") ''' To tackle 'The MySQL server is running with the --secure-file-priv option so it cannot execute this statement' error reference: https://blog.csdn.net/fdipzone/article/details/78634992 ''' # insert data into mysql table db_connection.insert_table("主資料表") db_connection.create_table("黑名單統計表") db_connection.insert_table("黑名單統計表") print("# 資料輸入資料庫成功,返回主選單") t_sleep(1) file_management.remove_temp()
def main(choice, delay): """" Loop through all available frequencies for the given processing unit """ frequencies = freq_available(choice) print(frequencies, flush=True) print( f"Current frequency is : {freq_mhz(choice, freq_current(choice))} Mhz", flush=True) for freq in frequencies: freq_write(choice, freq) counter = 0 while freq_current(choice) != freq: t_sleep(0.001) counter += 1 if counter > 1000: print( f"Frequency doesn't want to change, still at {freq_mhz(choice, freq_current(choice))} Mhz, " f"giving up", flush=True) break print( f"Current frequency is {freq_mhz(choice, freq_current(choice))} Mhz (waited {counter}ms). " f"Waiting {delay} sec to check the power consumption.", flush=True) t_sleep(delay) t_sleep(delay * 3) print("Tests are done, putting back to low power") freq_write(choice, frequencies[0]) print( f"Current frequency is {freq_mhz(choice, freq_current(choice))} Mhz (waited {counter}ms). " f"Waiting {delay} sec to check the power consumption.", flush=True)
def staStart(serv=(), chan={}, level=1): # easy workaround for windows (only for debug purposes) if v_system=="Windows": levelFlag = ("/F" if level==9 else "") fShell("taskkill %s /IM game /T"%(levelFlag)) fShell("taskkill %s /IM db /T"%(levelFlag)) return from time import sleep as t_sleep # szPWD=os_getcwd() global whichlist whichlist["serv"]=serv whichlist["chan"]=chan keyCheck(whichlist["chan"], "all", ()) def RunInMe(tmpProcList, bSkipCheck=False): for dic1 in tmpProcList: # skip not requested servers if (whichlist["serv"]) and (dic1["serv"] not in whichlist["serv"]): continue if not bSkipCheck and dic1["type"]==M2TYPE.CORE: # skip not requested channels keyCheck(whichlist["chan"], dic1["serv"], ()) if whichlist["chan"]["all"]: # print "all",whichlist["chan"]["all"] if not dic1["chan"] in whichlist["chan"]["all"]: continue if whichlist["chan"][dic1["serv"]]: # print dic1["serv"] if not dic1["chan"] in whichlist["chan"][dic1["serv"]]: continue # print dic1 szPID=fShell("""ps axf | fgrep "./%s" | fgrep -v grep | awk '{print $1}'"""%dic1["name"], True) if szPID: dwPID=int(szPID) # kill process fShell("kill -%u %u"%(level, dwPID)) print "%s -> %u"%(dic1["name"], dwPID) else: # do nothing print "%s -> not found"%dic1["name"] def CheckInMe(tmpProcList, bSkipCheck=False): for dic1 in tmpProcList: if (whichlist["serv"]) and (dic1["serv"] not in whichlist["serv"]): continue if not bSkipCheck and dic1["type"]==M2TYPE.CORE: keyCheck(whichlist["chan"], dic1["serv"], ()) if whichlist["chan"]["all"]: if not dic1["chan"] in whichlist["chan"]["all"]: continue if whichlist["chan"][dic1["serv"]]: if not dic1["chan"] in whichlist["chan"][dic1["serv"]]: continue szPID=fShell("""ps axf | fgrep "./%s" | fgrep -v grep | awk '{print $1}'"""%dic1["name"], True) if szPID: dwPID=int(szPID) print "still waiting for... %s -> %u"%(dic1["name"], dwPID) return False return True for k1 in proclist.iterkeys(): RunInMe(proclist[k1]["core"]) while not CheckInMe(proclist[k1]["core"]): t_sleep(3) t_sleep(3) RunInMe(proclist[k1]["db"])
def viewport_loop(): t = threading.current_thread() while t.name == 'run': virtual.refresh() t_sleep(sleep_time)
#!/usr/bin/env python3 import threading from subprocess import Popen, PIPE from time import sleep as t_sleep import sys proc = Popen(['python', 'test_subproc.py'], bufsize=1, stdout=PIPE, stdin=PIPE, universal_newlines=True) print('proc started') t_sleep(2) # print('done sleep') # print(proc.stdout) # print(proc.stdout.line_buffering) def write_commands(): proc.stdin.write( 'add playlist:https://st01.sslstream.dlf.de/dlf/01/high/aac/stream.aac\n' ) proc.stdin.write( 'add playlist:https://www.antennebrandenburg.de/live.m3u\n') proc.stdin.write('set playlist pos:0\n') proc.stdin.write('unmute:\nunpause:\n') proc.stdin.flush()