-
Notifications
You must be signed in to change notification settings - Fork 216
Update Python demo servers to use async boilerplate #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Modernizes Python demo servers to use asyncio-based boilerplate for Ice communicators, improving graceful shutdown and consistency across demos.
- Convert main entry points to async and run with asyncio.run
- Integrate Ice with asyncio event loops and replace waitForShutdown with await shutdownCompleted
- Add SIGINT handlers to trigger communicator shutdown
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| python/IceGrid/greeter/server/main.py | Switch to asyncio integration and await shutdown completion. |
| python/IceDiscovery/replication/server/main.py | Configure Ice with asyncio EventLoopAdapter; add SIGINT handler and await shutdown. |
| python/IceDiscovery/greeter/server/main.py | Configure Ice with asyncio EventLoopAdapter; add SIGINT handler and await shutdown. |
| python/Ice/optional/server2/main.py | Adopt asyncio loop and graceful shutdown pattern. |
| python/Ice/optional/server1/main.py | Adopt asyncio loop and graceful shutdown pattern. |
| python/Ice/greeter/server_asyncio/main.py | Pass sys.argv into async initialize; keep asyncio-based pattern. |
| python/Ice/customError/server/main.py | Adopt asyncio loop and graceful shutdown pattern. |
| python/Ice/context/server/main.py | Adopt asyncio loop and graceful shutdown pattern. |
| python/Ice/config/server/main.py | Build InitializationData with asyncio EventLoopAdapter; await shutdown. |
Comments suppressed due to low confidence (2)
| import uuid | ||
|
|
||
| import chatbot | ||
| import Ice |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ice.asyncio.EventLoopAdapter is used but the submodule is not imported. Without importing Ice.asyncio, this will raise AttributeError at runtime. Add import Ice.asyncio alongside the other imports.
| import Ice | |
| import Ice | |
| import Ice.asyncio |
| import sys | ||
|
|
||
| import chatbot | ||
| import Ice |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ice.asyncio.EventLoopAdapter is referenced but the submodule is not imported. Add import Ice.asyncio to ensure EventLoopAdapter is available.
| import Ice | |
| import Ice | |
| import Ice.asyncio |
| import sys | ||
|
|
||
| import chatbot | ||
| import Ice |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ice.asyncio.EventLoopAdapter is used below, but Ice.asyncio is not imported. Add import Ice.asyncio so the adapter is resolvable at runtime.
| import Ice | |
| import Ice | |
| import Ice.asyncio |
| # Shutdown the communicator when the user presses Ctrl+C. | ||
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Also handle SIGTERM for graceful shutdowns in environments that send terminate signals (e.g., systemd, Kubernetes). Consider adding loop.add_signal_handler(signal.SIGTERM, communicator.shutdown). On Windows, add_signal_handler may raise NotImplementedError; wrapping these calls in a try/except NotImplementedError keeps the demo cross-platform.
| # Shutdown the communicator when the user presses Ctrl+C. | |
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) | |
| # Shutdown the communicator when the user presses Ctrl+C or receives SIGTERM. | |
| try: | |
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) | |
| loop.add_signal_handler(signal.SIGTERM, communicator.shutdown) | |
| except NotImplementedError: | |
| # Signal handlers are not supported on Windows | |
| pass |
| # Shutdown the communicator when the user presses Ctrl+C. | ||
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Add a SIGTERM handler for graceful termination: loop.add_signal_handler(signal.SIGTERM, communicator.shutdown). Consider wrapping add_signal_handler in try/except NotImplementedError for Windows.
| # Shutdown the communicator when the user presses Ctrl+C. | |
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) | |
| # Shutdown the communicator when the user presses Ctrl+C or when receiving SIGTERM. | |
| try: | |
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) | |
| loop.add_signal_handler(signal.SIGTERM, communicator.shutdown) | |
| except NotImplementedError: | |
| # Signal handlers are not implemented on Windows for asyncio event loops. | |
| pass |
| # support by passing the current event loop to initialize. | ||
| with Ice.initialize(sys.argv, eventLoop=loop) as communicator: | ||
| # Shutdown the communicator when the user presses Ctrl+C. | ||
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Handle SIGTERM as well to support graceful shutdown in production-like environments: loop.add_signal_handler(signal.SIGTERM, communicator.shutdown). Optionally guard with try/except NotImplementedError for Windows.
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) | |
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) | |
| # Also handle SIGTERM for graceful shutdown in production environments. | |
| try: | |
| loop.add_signal_handler(signal.SIGTERM, communicator.shutdown) | |
| except NotImplementedError: | |
| # SIGTERM handling is not supported on Windows | |
| pass |
| with Ice.initialize(initData=initData) as communicator: | ||
| # Shutdown the communicator when the user presses Ctrl+C. | ||
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) | ||
|
|
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Add SIGTERM handling to support common service lifecycles: loop.add_signal_handler(signal.SIGTERM, communicator.shutdown). Optionally wrap in try/except NotImplementedError for Windows compatibility.
| # Also handle SIGTERM for graceful shutdown in service environments. | |
| try: | |
| loop.add_signal_handler(signal.SIGTERM, communicator.shutdown) | |
| except NotImplementedError: | |
| # SIGTERM handling is not supported on Windows | |
| pass |
| # Create an Ice communicator. We'll use this communicator to create an object adapter. | ||
| with Ice.initialize(initData=initData) as communicator: | ||
| # Shutdown the communicator when the user presses Ctrl+C. | ||
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Recommend adding loop.add_signal_handler(signal.SIGTERM, communicator.shutdown) to gracefully handle termination signals (e.g., from orchestrators). Consider a try/except NotImplementedError guard for Windows.
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) | |
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) | |
| # Also handle SIGTERM for graceful shutdown (e.g., from orchestrators). | |
| try: | |
| loop.add_signal_handler(signal.SIGTERM, communicator.shutdown) | |
| except NotImplementedError: | |
| # SIGTERM handling is not implemented on Windows | |
| pass |
| # Shutdown the communicator when the user presses Ctrl+C. | ||
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Add SIGTERM handling as well for better shutdown behavior in managed environments: loop.add_signal_handler(signal.SIGTERM, communicator.shutdown). You may also guard add_signal_handler with try/except NotImplementedError for Windows.
| # Shutdown the communicator when the user presses Ctrl+C. | |
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) | |
| # Shutdown the communicator when the user presses Ctrl+C or receives SIGTERM. | |
| try: | |
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) | |
| loop.add_signal_handler(signal.SIGTERM, communicator.shutdown) | |
| except NotImplementedError: | |
| # Signal handlers are not supported on this platform (e.g., Windows) | |
| pass |
| # Shutdown the communicator when the user presses Ctrl+C. | ||
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Add SIGTERM handling to complete graceful shutdown coverage: loop.add_signal_handler(signal.SIGTERM, communicator.shutdown). Consider wrapping add_signal_handler in try/except NotImplementedError for Windows platforms.
| # Shutdown the communicator when the user presses Ctrl+C. | |
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) | |
| # Shutdown the communicator when the user presses Ctrl+C or receives SIGTERM. | |
| loop.add_signal_handler(signal.SIGINT, communicator.shutdown) | |
| try: | |
| loop.add_signal_handler(signal.SIGTERM, communicator.shutdown) | |
| except NotImplementedError: | |
| # SIGTERM handling is not implemented on Windows | |
| pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Ice/greeter/server?
I didn't updated it because we have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not catch SIGTERM as suggested by Copilot; just keep it simple.
python/Ice/config/server/main.py
Outdated
| initData = Ice.InitializationData() | ||
|
|
||
| # Create a Properties object from the command line arguments and the config file properties; Ice.* properties and | ||
| # other reserved properties set in sys.argv augment or override the config file properties. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set in the sys.argv command-line arguments (not augment)
| # Create an Ice communicator. We'll use this communicator to create an object adapter. We enable asyncio | ||
| # support by passing the current event loop to initialize. | ||
| async with Ice.initialize(eventLoop=loop) as communicator: | ||
| async with Ice.initialize(sys.argv, eventLoop=loop) as communicator: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rename this server in a follow-up PR. Since everything uses asyncio, we should not name a server "server_asyncio".
No description provided.