def test_windows_event_loop_fix(): async def _asyncio_test(): await asyncio.create_subprocess_shell("") yapapi.windows_event_loop_fix() l = asyncio.get_event_loop() t = l.create_task(_asyncio_test()) l.run_until_complete(t)
def run_golem_example(example_main, log_file=None): # This is only required when running on Windows with Python prior to 3.8: windows_event_loop_fix() if log_file: enable_default_logger( log_file=log_file, debug_activity_api=True, debug_market_api=True, debug_payment_api=True, debug_net_api=True, ) loop = asyncio.get_event_loop() task = loop.create_task(example_main) try: loop.run_until_complete(task) except NoPaymentAccountError as e: handbook_url = ( "https://handbook.golem.network/requestor-tutorials/" "flash-tutorial-of-requestor-development" ) print( f"{TEXT_COLOR_RED}" f"No payment account initialized for driver `{e.required_driver}` " f"and network `{e.required_network}`.\n\n" f"See {handbook_url} on how to initialize payment accounts for a requestor node." f"{TEXT_COLOR_DEFAULT}" ) except KeyboardInterrupt: print( f"{TEXT_COLOR_YELLOW}" "Shutting down gracefully, please wait a short while " "or press Ctrl+C to exit immediately..." f"{TEXT_COLOR_DEFAULT}" ) task.cancel() try: loop.run_until_complete(task) print( f"{TEXT_COLOR_YELLOW}Shutdown completed, thank you for waiting!{TEXT_COLOR_DEFAULT}" ) except (asyncio.CancelledError, KeyboardInterrupt): pass
f"{TEXT_COLOR_DEFAULT}") print( f"{TEXT_COLOR_CYAN}" f"{num_tasks} tasks computed, total time: {datetime.now() - start_time}" f"{TEXT_COLOR_DEFAULT}") if __name__ == "__main__": parser = build_parser("Send a drone task") now = datetime.now().strftime("%Y-%m-%d_%H.%M.%S") parser.set_defaults(log_file=f"drone-yapapi-{now}.log") args = parser.parse_args() # This is only required when running on Windows with Python prior to 3.8: windows_event_loop_fix() enable_default_logger( log_file=args.log_file, debug_activity_api=True, debug_market_api=True, debug_payment_api=True, ) loop = asyncio.get_event_loop() task = loop.create_task( main( subnet_tag=args.subnet_tag, payment_driver=args.payment_driver, payment_network=args.payment_network, ))