---
title: "Communicator"
url: https://docs.zeroc.com/ice/3.8/runtime/communicator
language: python
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Communicator

Programming language: Python. Other languages: [C++](https://docs.zeroc.com/ice/3.8/runtime/communicator/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/runtime/communicator/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/runtime/communicator/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/runtime/communicator/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/runtime/communicator/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/runtime/communicator/php.md), [Ruby](https://docs.zeroc.com/ice/3.8/runtime/communicator/ruby.md), [Swift](https://docs.zeroc.com/ice/3.8/runtime/communicator/swift.md).

A [communicator](https://code.zeroc.com/ice/3.8/api/python/Ice.Communicator.html) is the entry point into the Ice runtime. You create proxies with a communicator, and each communicator has its own:

- **Outgoing connections** The communicator establishes and caches the connections that invocations on its proxies use.
- **Client-side thread pool** This [thread pool](https://docs.zeroc.com/ice/3.8/runtime/threading-model.md) processes the messages received on the outgoing connections.
- **Object adapters** The communicator creates the [object adapters](https://docs.zeroc.com/ice/3.8/runtime/dispatch/python.md) that dispatch incoming requests to your servants.
- **Properties** Each communicator holds a [property set](https://docs.zeroc.com/ice/3.8/runtime/properties-and-configuration/python.md). These properties configure this communicator, and an Ice service or an application that uses this communicator can read its own properties from the same set.
- **Logger** The [logger](https://docs.zeroc.com/ice/3.8/administration/logger-facility/python.md) of a communicator receives the log messages of the Ice runtime.

Most applications use a single communicator, but an application can create several communicators when needed.

## Creating a Communicator

You create a communicator by using its constructor, for example:

```py
import Ice
import sys

def main():
    with Ice.Communicator(sys.argv) as communicator:
        ...
```

The `Ice.Communicator` constructor takes the command-line arguments of the program. It [sets a property](https://docs.zeroc.com/ice/3.8/runtime/properties-and-configuration/setting-properties-on-the-command-line.md) for each argument that names an Ice property, and removes these arguments from the list.

`Communicator` implements the [Python context manager protocol](https://peps.python.org/pep-0343/), which cleans up the communicator automatically at the end of the with block.

`async with` is preferred in an async context. For example:

```py
import Ice
import asyncio
import sys

async def main():
    async with Ice.Communicator(
        sys.argv,
        eventLoop=asyncio.get_running_loop()) as communicator:
        ...
```

## Destroying a Communicator

Destroy a communicator when you no longer need it. Destroying a communicator closes its connections, destroys its object adapters, waits for the dispatches that are still running to complete, and releases its resources.

## Initialization Data

[InitializationData](https://code.zeroc.com/ice/3.8/api/python/Ice.InitializationData.html) holds the options you can supply when you create a communicator, such as its properties and its logger. Set these options in an `InitializationData` object, and create the communicator with this object.

The constructor takes either the command-line arguments or an `InitializationData`. To set properties from the arguments when you pass initialization data, create the properties from the arguments and set them in the initialization data:

```py
initData = Ice.InitializationData()
initData.properties = Ice.Properties(sys.argv)
# ... set other initData fields ...
with Ice.Communicator(initData=initData) as communicator:
    ...
```

## See Also

- [Setting Properties on the Command Line](https://docs.zeroc.com/ice/3.8/runtime/properties-and-configuration/setting-properties-on-the-command-line.md)
- [The Properties Class](https://docs.zeroc.com/ice/3.8/runtime/properties-and-configuration/properties-class/python.md)
