-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update src/napari_chatgpt/utils/network/demo/port_available_demo.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
97e3a26
commit 7b9d7c5
Showing
1 changed file
with
10 additions
and
14 deletions.
There are no files selected for viewing
24 changes: 10 additions & 14 deletions
24
src/napari_chatgpt/utils/network/demo/port_available_demo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |