try to avoid thread exception

This commit is contained in:
2022-03-28 19:34:09 +02:00
parent b486aa75d9
commit ff9753dd87
+6 -3
View File
@@ -33,6 +33,8 @@ class CommandorPage:
def _run(self, e: threading.Event, proxy, contact: ContactPojo, on_ready_for_otp, on_success): def _run(self, e: threading.Event, proxy, contact: ContactPojo, on_ready_for_otp, on_success):
self.contact = contact self.contact = contact
self.on_success_listener = on_success self.on_success_listener = on_success
# reset otp_value to None
self.otp_value = None
with sync_playwright() as pwright: with sync_playwright() as pwright:
firefox_user_agents = filter(lambda user_agent: "firefox" in user_agent.lower(), user_agent_list) firefox_user_agents = filter(lambda user_agent: "firefox" in user_agent.lower(), user_agent_list)
firefox_user_agents_list = list(firefox_user_agents) firefox_user_agents_list = list(firefox_user_agents)
@@ -69,9 +71,9 @@ class CommandorPage:
logging.info('event set: %s', event_is_set) logging.info('event set: %s', event_is_set)
if self.otp_value: if self.otp_value:
self.fill_otp(self.otp_value) self.fill_otp(self.otp_value)
self.clickOnValidBtn() self.clickOnValidBtn()
otp_sent = self.page.locator(MESSAGE_FIELD_CLASS) otp_sent = self.page.locator(MESSAGE_FIELD_CLASS)
otp_sent.wait_for(state='visible') otp_sent.wait_for(state='visible')
message = self.page.content() message = self.page.content()
# print("message is:" + message) # print("message is:" + message)
time.sleep(2) time.sleep(2)
@@ -97,6 +99,7 @@ class CommandorPage:
return self.page.content() return self.page.content()
except Exception as error: except Exception as error:
self.logger.exception(error) self.logger.exception(error)
self.browser.close()
return None return None
def start_page(self, proxy, contact: ContactPojo, on_ready_for_otp, on_sucess) -> threading.Event: def start_page(self, proxy, contact: ContactPojo, on_ready_for_otp, on_sucess) -> threading.Event: