This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
ipc-unix/README.md

49 lines
1.2 KiB
Markdown
Raw Normal View History

2018-12-07 14:07:35 +00:00
# IPC-Unix
[![CircleCI](https://circleci.com/gh/RealOrangeOne/ipc-unix.svg?style=svg)](https://circleci.com/gh/RealOrangeOne/ipc-unix)
2018-12-08 15:41:16 +00:00
[![Build Status](https://travis-ci.com/RealOrangeOne/ipc-unix.svg?branch=master)](https://travis-ci.com/RealOrangeOne/ipc-unix)
2018-12-07 14:07:35 +00:00
Simple Inter-Process Communication using unix sockets for Python.
2018-12-08 14:47:07 +00:00
2018-12-08 15:06:33 +00:00
__Note__: Whilst mostly working, there's still some fairly common cases which haven't been tested. Use at your own risk until this message is removed.
2018-12-08 14:47:07 +00:00
## Examples
2018-12-08 14:50:04 +00:00
For some more concrete examples, check out the `tests/` directory.
2018-12-08 14:47:07 +00:00
### Call / Response
```python
from ipc_unix import Server, Client
class EchoServer(Server):
def handle_request(self, request):
return request
socket_path = '/tmp/sock.sock'
server = EchoServer(socket_path)
client = Client(socket_path)
print(client.send({"foo": "bar"}))
>>> {"foo": "bar"}
```
### Pub-Sub
```python
from ipc_unix import pubsub
socket_path = '/tmp/sock.sock'
publisher = pubsub.Publisher(socket_path)
subscriber = pubsub.Subscriber(socket_path)
publisher.write({"foo": "bar"})
print(self.subscriber.get_latest_message())
>>> {"foo": "bar"}
publisher.close()
subscriber.close()
```