Skip to content

Commit

Permalink
Always explicitly create event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
SaladDais committed Jan 10, 2024
1 parent 67ab33e commit 8f2ade1
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def amain():
print(await viewer_control_api.get("Global", "StatsPilotFile"), file=sys.stderr)


loop = asyncio.get_event_loop_policy().get_event_loop()
loop = asyncio.new_event_loop()
loop.run_until_complete(amain())
```

Expand Down
2 changes: 1 addition & 1 deletion examples/complex_leap_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def client_connected(client: LEAPClient):

def receiver_main():
logging.basicConfig(level=logging.INFO)
loop = asyncio.get_event_loop_policy().get_event_loop()
loop = asyncio.new_event_loop()

args = sys.argv[1:]
if args and args[0] == "--tcp":
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_leap_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async def amain():


def main():
loop = asyncio.get_event_loop_policy().get_event_loop()
loop = asyncio.new_event_loop()
loop.run_until_complete(amain())


Expand Down
2 changes: 1 addition & 1 deletion src/outleap/scripts/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def amain():


def agent_main():
loop = asyncio.get_event_loop_policy().get_event_loop()
loop = asyncio.new_event_loop()
loop.run_until_complete(amain())


Expand Down
2 changes: 1 addition & 1 deletion src/outleap/scripts/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def client_connected(self, client: outleap.LEAPClient):

def repl_main():
logging.basicConfig()
loop = asyncio.get_event_loop_policy().get_event_loop()
loop = asyncio.new_event_loop()
repl_server = REPLServer()
server = outleap.LEAPBridgeServer(repl_server.client_connected)
coro = asyncio.start_server(server.handle_connection, "127.0.0.1", 9063)
Expand Down
4 changes: 2 additions & 2 deletions src/outleap/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def _make_hacky_threaded_stdio_rw() -> Tuple[asyncio.StreamReader, asyncio
#
# TODO: Currently we also use this if we're reading from a non-pipe file descriptor on POSIX
# platforms, but that's probably unnecessary.
loop = asyncio.get_event_loop_policy().get_event_loop()
loop = asyncio.get_event_loop()
reader = asyncio.StreamReader(limit=_READER_BUFFER_LIMIT)
protocol = HackySTDIOProtocol()
transport = HackySTDIOTransport()
Expand Down Expand Up @@ -157,7 +157,7 @@ async def connect_stdin_stdout() -> Tuple[asyncio.StreamReader, asyncio.StreamWr
need_stdin_hack = True
if need_stdin_hack:
return await _make_hacky_threaded_stdio_rw()
loop = asyncio.get_event_loop_policy().get_event_loop()
loop = asyncio.get_event_loop()
reader = asyncio.StreamReader(limit=_READER_BUFFER_LIMIT)
protocol = asyncio.StreamReaderProtocol(reader)
await loop.connect_read_pipe(lambda: protocol, sys.stdin)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_stdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def amain():
# Ask for a config value and print it in the viewer logs
await viewer_control_api.get("Global", "StatsPilotFile")
loop = asyncio.get_event_loop_policy().get_event_loop()
loop = asyncio.new_event_loop()
loop.run_until_complete(amain())
"""

Expand Down

0 comments on commit 8f2ade1

Please sign in to comment.