test_bg_scan_state.assertReady() test_bg_scan_state = State.Busy test_bg_scan_result = None try: caput("STATS:TESTVALUE4", 11) test_bg_scan_result = "Ok" except: test_bg_scan_result = str(sys.exc_info()[1]) finally: #Make sure add this in the finally, otherwise you may get blocked test_bg_scan_state = State.Ready