Commit 0b095322 authored by Lee Lunn's avatar Lee Lunn Committed by GitHub

[FIX] Lookup raises in threaded environment. See note. (#688)

In threaded applications, if the user does not explictly create a new 
event loop then one does not exist.
parent f311a949
...@@ -258,13 +258,37 @@ def Following(config): ...@@ -258,13 +258,37 @@ def Following(config):
def Lookup(config): def Lookup(config):
logme.debug(__name__+':Lookup') logme.debug(__name__+':Lookup')
try:
get_event_loop()
except RuntimeError as e:
if "no current event loop" in str(e):
set_event_loop(new_event_loop())
else:
logme.exception(__name__+':Lookup:Unexpected exception while handling an expected RuntimeError.')
raise
except Exception as e:
logme.exception(__name__+':Lookup:Unexpected exception occured while attempting to get or create a new event loop.')
raise
try:
if config.User_id is not None: if config.User_id is not None:
logme.debug(__name__+':Twint:Lookup:user_id') logme.debug(__name__+':Twint:Lookup:user_id')
config.Username = get_event_loop().run_until_complete(get.Username(config.User_id)) config.Username = get_event_loop().run_until_complete(get.Username(config.User_id))
url = f"https://twitter.com/{config.Username}?lang=en" url = f"https://twitter.com/{config.Username}?lang=en"
get_event_loop().run_until_complete(get.User(url, config, db.Conn(config.Database))) get_event_loop().run_until_complete(get.User(url, config, db.Conn(config.Database)))
if config.Pandas_au: if config.Pandas_au:
storage.panda._autoget("user") storage.panda._autoget("user")
except RuntimeError as e:
if "no current event loop" in str(e):
logme.exception(__name__+':Lookup:Previous attempt to to create an event loop failed.')
raise
except Exception as e:
logme.exception(__name__+':Lookup:Unexpected exception occured.')
raise
def Profile(config): def Profile(config):
logme.debug(__name__+':Profile') logme.debug(__name__+':Profile')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment