Skip to content

Commit

Permalink
Update src/napari_chatgpt/utils/network/demo/port_available_demo.py
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
royerloic and coderabbitai[bot] authored Aug 28, 2024
1 parent 97e3a26 commit 7b9d7c5
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/napari_chatgpt/utils/network/demo/port_available_demo.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
# main to test automatic port increment in the omega server:
if __name__ == '__main__':
# now start a simple server asynchronously on that port to occupy it:
import asyncio
from aiohttp import web


# Define a simple handler that returns a simple response:
async def handle(request):
return web.Response(text="Hello, world")


# Start the server:
app = web.Application()
app.router.add_get('/', handle)
runner = web.AppRunner(app)
loop = asyncio.get_event_loop()
loop.run_until_complete(runner.setup())
site = web.TCPSite(runner, 'localhost', 9000)

# Start the server:
loop.run_until_complete(site.start())

# wait until key pressed on terminal:
input("Press Enter to continue...")
loop.run_until_complete(runner.cleanup())
loop.close()
try:
loop.run_until_complete(runner.setup())
site = web.TCPSite(runner, 'localhost', 9000)
loop.run_until_complete(site.start())
input("Press Enter to continue...")
except Exception as e:
print(f"Error occurred: {e}")
finally:
loop.run_until_complete(runner.cleanup())
loop.close()

0 comments on commit 7b9d7c5

Please sign in to comment.