Check Connection

Using mavlink command [mavutil.mavlink_connection('udpin:port_num),
wait_heartbeat()] like this we can check the connection, but there is a problem like, won’t be receiving an acknowledgement if there is no connection. In programing point this gives trouble by stuck in this line when there is connection issue and waiting for heartbeat. Is there any other better way to check connection ?