forked from fyears/electron-python-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
33 lines (29 loc) · 741 Bytes
/
api.py
File metadata and controls
33 lines (29 loc) · 741 Bytes
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
from __future__ import print_function
from calc import calc as real_calc
import sys
import zerorpc
class CalcApi(object):
def calc(self, text):
"""based on the input text, return the int result"""
try:
return real_calc(text)
except Exception as e:
return 0.0
def echo(self, text):
"""echo any text"""
return text
def parse_port():
port = 4242
try:
port = int(sys.argv[1])
except Exception as e:
pass
return '{}'.format(port)
def main():
addr = 'tcp://127.0.0.1:' + parse_port()
s = zerorpc.Server(CalcApi())
s.bind(addr)
print('start running on {}'.format(addr))
s.run()
if __name__ == '__main__':
main()