Skip to content

Commit ac45e80

Browse files
committedFeb 11, 2025
no eventloop on android?
1 parent b9976b6 commit ac45e80

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed
 

‎pwnlib/tubes/remote.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,17 @@ async def async_getaddrinfo(host, port, fam=0, typ=0, proto=0, flags=0):
122122
# to use async all the ways to `sock.connect`. However, let's keep the changes
123123
# small until we have the needs.
124124
def sync_getaddrinfo(*args):
125-
loop = asyncio.get_event_loop()
126125
coro = async_getaddrinfo(*args)
127-
if loop.is_running():
128-
# If an event loop is already running, use it to run the async function
129-
future = asyncio.run_coroutine_threadsafe(coro, loop)
130-
return future.result()
131-
else:
132-
# If no event loop is running, create a new one
133-
return asyncio.run(coro)
126+
try:
127+
loop = asyncio.get_event_loop()
128+
if loop.is_running():
129+
# If an event loop is already running, use it to run the async function
130+
future = asyncio.run_coroutine_threadsafe(coro, loop)
131+
return future.result()
132+
except RuntimeError:
133+
pass
134+
# If no event loop is running, create a new one
135+
return asyncio.run(coro)
134136

135137
with self.waitfor('Opening connection to %s on port %s' % (self.rhost, self.rport)) as h:
136138
hostnames = sync_getaddrinfo(self.rhost, self.rport, fam, typ, 0, socket.AI_PASSIVE)

0 commit comments

Comments
 (0)