Skip to content

Conversation

@pepone
Copy link
Member

@pepone pepone commented Oct 16, 2025

No description provided.

Copy link

Copilot AI left a 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
Copy link

Copilot AI Oct 16, 2025

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.

Suggested change
import Ice
import Ice
import Ice.asyncio

Copilot uses AI. Check for mistakes.
import sys

import chatbot
import Ice
Copy link

Copilot AI Oct 16, 2025

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.

Suggested change
import Ice
import Ice
import Ice.asyncio

Copilot uses AI. Check for mistakes.
import sys

import chatbot
import Ice
Copy link

Copilot AI Oct 16, 2025

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.

Suggested change
import Ice
import Ice
import Ice.asyncio

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +19
# Shutdown the communicator when the user presses Ctrl+C.
loop.add_signal_handler(signal.SIGINT, communicator.shutdown)
Copy link

Copilot AI Oct 16, 2025

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.

Suggested change
# 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

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +18
# Shutdown the communicator when the user presses Ctrl+C.
loop.add_signal_handler(signal.SIGINT, communicator.shutdown)
Copy link

Copilot AI Oct 16, 2025

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.

Suggested change
# 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

Copilot uses AI. Check for mistakes.
# 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)
Copy link

Copilot AI Oct 16, 2025

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
with Ice.initialize(initData=initData) as communicator:
# Shutdown the communicator when the user presses Ctrl+C.
loop.add_signal_handler(signal.SIGINT, communicator.shutdown)

Copy link

Copilot AI Oct 16, 2025

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.

Suggested change
# 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

Copilot uses AI. Check for mistakes.
# 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)
Copy link

Copilot AI Oct 16, 2025

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines 18 to 19
# Shutdown the communicator when the user presses Ctrl+C.
loop.add_signal_handler(signal.SIGINT, communicator.shutdown)
Copy link

Copilot AI Oct 16, 2025

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.

Suggested change
# 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

Copilot uses AI. Check for mistakes.
Comment on lines +30 to +31
# Shutdown the communicator when the user presses Ctrl+C.
loop.add_signal_handler(signal.SIGINT, communicator.shutdown)
Copy link

Copilot AI Oct 16, 2025

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.

Suggested change
# 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

Copilot uses AI. Check for mistakes.
Copy link
Member

@externl externl left a 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?

@pepone
Copy link
Member Author

pepone commented Oct 16, 2025

Ice/greeter/server?

I didn't updated it because we have server_asyncio in the same demo, but maybe we should too.

Copy link
Member

@bernardnormier bernardnormier left a 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.

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.
Copy link
Member

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:
Copy link
Member

@bernardnormier bernardnormier Oct 16, 2025

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".

@pepone pepone merged commit 4a7267c into zeroc-ice:main Oct 17, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants