diff --git a/dwmbar b/dwmbar index d5b9804..99811f1 100755 --- a/dwmbar +++ b/dwmbar @@ -12,13 +12,12 @@ from datetime import datetime DD = ';' DELIM = ' ' -COLOR = False +COLOR = True def shutdown(): - for task in asyncio.Task.all_tasks(): - if task is not asyncio.tasks.Task.current_task(): - task.cancel() + print("Shutting down...") + loop.stop() async def dwmbar(): @@ -63,24 +62,9 @@ async def bl(): while True: curs = [] - curs.append(['', f"${float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=XMRUSDT').json()['lastPrice']):.2f}"]) curs.append(['', f"${float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=BTCUSDT').json()['lastPrice']):.2f}"]) curs.append(['', f"${float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=LTCUSDT').json()['lastPrice']):.2f}"]) curs.append(['Ð', f"${float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=DOGEUSDT').json()['lastPrice']):.2f}"]) - curs.append(['$', f"{float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=USDTRUB').json()['lastPrice']):.2f} RUB"]) - - curs.append(['', - f"""{ - float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=USDTRUB').json()['lastPrice']) / - float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=USDTTRY').json()['lastPrice']) - :.2f} RUB""" - ]) - curs.append(['₴', - f"""{ - float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=USDTRUB').json()['lastPrice']) / - float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=USDTUAH').json()['lastPrice']) - :.2f} RUB""" - ]) if COLOR: row = list(map(lambda x: f'^b{COLOR1}^^c{COLOR2}^ {x[0]} ^c{COLOR1}^^b{COLOR2}^ {x[1]} ^d^', curs)) @@ -182,7 +166,7 @@ async def gpu(): COLOR2='#FF00B2' while True: - load = open('/sys/class/drm/card0/device/gpu_busy_percent').read().strip() + load = open('/sys/class/drm/card1/device/gpu_busy_percent').read().strip() if COLOR: gpu = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {load}% ^d^' @@ -307,11 +291,8 @@ async def dat(): await asyncio.sleep(1) -if __name__ == '__main__': - signal.signal(signal.SIGINT, lambda n, f: shutdown()) - - loop = asyncio.get_event_loop() - main_task = asyncio.wait([ +async def main(): + await asyncio.gather( dwmbar(), net(), ram(), @@ -324,10 +305,18 @@ if __name__ == '__main__': tim(), bl(), br() - ]) + ) + + +if __name__ == '__main__': + signal.signal(signal.SIGINT, lambda n, f: shutdown()) + + loop = asyncio.get_event_loop() + main_task = asyncio.ensure_future(main()) try: loop.run_until_complete(main_task) - except asyncio.CancelledError: - loop.run_until_complete(main_task) - loop.close() + except KeyboardInterrupt: + print("KeyboardInterrupt: Stopping the event loop...") + finally: + loop.close()