Eliminate dependence on time.sleep()