When I start a quick tunnel as follows,how can I stop the tunnel_task?I use the "rsd.close()" 3 second after "asyncio.create_task",but it did not work。
async def tunnel_task(
service_provider: RemoteServiceDiscoveryService, secrets: TextIO,
script_mode: bool = False, max_idle_timeout: float = MAX_IDLE_TIMEOUT,
protocol: TunnelProtocol = TunnelProtocol.QUIC) -> None:
if start_tunnel is None:
raise NotImplementedError('failed to start the QUIC tunnel on your platform')
async with start_tunnel(service_provider, secrets=secrets, max_idle_timeout=max_idle_timeout,
protocol=protocol) as tunnel_result:
logger.info('tunnel created')
print(f"ProductType: {service_provider.product_type}")
print(f"ProductVersion: {service_provider.product_version}")
print(f"Interface: {tunnel_result.interface}")
print(f"Protocol: {tunnel_result.protocol}")
print(f"RSD Address: {tunnel_result.address}")
print(f"RSD Port: {tunnel_result.port}")
print(f"Use the follow connection option:\n--rsd {tunnel_result.address} {tunnel_result.port}")
sys.stdout.flush()
await tunnel_result.client.wait_closed()
logger.info('tunnel was closed')
protocol = TunnelProtocol('quic')
udid = '00008130-0009488E3E10001C'
protocol = TunnelProtocol(protocol)
if not verify_tunnel_imports():
pass
devices = get_device_list()
rsd:RemoteServiceDiscoveryService|None = None
if not devices:
# no devices were found
raise NoDeviceConnectedError()
if len(devices) == 1:
# only one device found
rsd = devices[0]
else:
rsd = [device for device in devices if device.udid == udid]
if len(rsd) > 0:
rsd = rsd[0]
else:
raise NoDeviceConnectedError()
if udid is not None and rsd.udid != udid:
raise NoDeviceConnectedError()
# asyncio.run(tunnel_task(rsd, None, False, max_idle_timeout=MAX_IDLE_TIMEOUT, protocol=protocol),
# debug=True)
async def main():
asyncio.create_task(tunnel_task(rsd, None, False, max_idle_timeout=MAX_IDLE_TIMEOUT, protocol=protocol))
print("111-----------------111")
await asyncio.sleep(3)
rsd.close()
loop = asyncio.get_event_loop()
loop.set_debug(True)
loop.run_until_complete(main())
while(True):
pass
When I start a quick tunnel as follows,how can I stop the tunnel_task?I use the "rsd.close()" 3 second after "asyncio.create_task",but it did not work。