-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpickle_receive.py
70 lines (54 loc) · 1.95 KB
/
pickle_receive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# pyplexo
# Copyright © 2018-2023 Alecks Gates
#
# pyplexo is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyplexo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with pyplexo. If not, see <https://www.gnu.org/licenses/>.
import asyncio
import ipaddress
import logging
from typing import Optional
from uuid import UUID
from plexo.codec.pickle_codec import PickleCodec
from plexo.neuron.neuron import Neuron
from plexo.ganglion.plexo_multicast import GanglionPlexoMulticast
from plexo.namespace.namespace import Namespace
test_multicast_cidr = ipaddress.ip_network("239.255.0.0/16")
test_port = 5561
class Foo:
message: str
async def _foo_reaction(
data: Foo, neuron: Neuron[Foo], reaction_id: Optional[UUID] = None
):
logging.info(f"Received Foo.string: {data.message}")
def run(loop=None):
logging.basicConfig(level=logging.DEBUG)
if not loop: # pragma: no cover
loop = asyncio.new_event_loop()
ganglion = GanglionPlexoMulticast(
multicast_cidr=test_multicast_cidr,
port=test_port,
heartbeat_interval_seconds=10,
)
namespace = Namespace(["dev", "plexo", "test"])
foo_neuron = Neuron(Foo, namespace, PickleCodec())
asyncio.run(ganglion.adapt(foo_neuron, reactants=[_foo_reaction]))
if not loop.is_running(): # pragma: no cover
try:
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
loop.close()
ganglion.close()
if __name__ == "__main__":
run()