-
Notifications
You must be signed in to change notification settings - Fork 0
/
fakemodule.py
53 lines (40 loc) · 1.28 KB
/
fakemodule.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
#!/usr/bin/env python
"""fakemodule.py: Module Description ..."""
from __future__ import print_function
import util.projectpath
import gevent
from nodemodule import NodeModule
from colorlogger import CLogger as log
__author__ = "Minos Galanakis"
__license__ = "LGPL"
__version__ = "X.X.X"
__email__ = "[email protected]"
__project__ = "codename"
__date__ = "26-06-2017"
log.setup(__file__, util.projectpath.log_level)
class fakeNodeModule(NodeModule):
def node_init(self):
""" Initialisation of node """
self.message_base = "Hello %d"
self.counter = 0
def node_main(self):
""" User implemented main loop for node """
test_msg_pl = self.messenger.new_service("Hello %d" % self.counter)
test_msg = self.messenger.solicited_msg(test_msg_pl)
self.send_msg(test_msg)
log.info("Nodemodule: Sending")
print(test_msg)
gevent.sleep(0.3)
if self.has_msg():
log.info("Nodemodule: Received")
rep = self.get_msg(blk=True)
print("%s" % rep)
self.counter += 1
if __name__ == "__main__":
NM = fakeNodeModule(modulename="FakeModule")
try:
while True:
gevent.sleep(1)
except KeyboardInterrupt:
NM.stop()
NM.join(timeout=5)