-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (56 loc) · 1.44 KB
/
main.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
#!/usr/bin/env python
import sys
import os
import argparse
from tcpserver import TCPServer
import socket
from chord import ChordNode
def startlisten(tcpserver):
try:
pid = os.fork()
except Exception, e:
raise e
if (pid == 0):
try:
print "Starting Listener"
tcpserver.initlistener()
except Exception, e:
raise e
finally:
os._exit(0)
def startTCP(tcpserver):
try:
pid = os.fork()
except Exception, e:
raise e
if (pid == 0):
try:
print "Starting TCPServer"
tcpserver.initserver()
except Exception, e:
raise e
finally:
os._exit(0)
def main():
# parse command line options
parser = argparse.ArgumentParser()
parser.add_argument('-p', type=int, default=7000)
parser.add_argument('-a', type=str, required=True)
parser.add_argument('-s', type=int, default=8080)
parser.add_argument('-i', type=str, required=True)
parser.add_argument('-c', type=str, required=True)
args = parser.parse_args()
tcpserver = TCPServer(args.a, args.i, args.p, args.s, args.c)
startlisten(tcpserver)
startTCP(tcpserver)
while True:
pass
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print 'Interrupted'
try:
sys.exit(0)
except SystemExit:
os._exit(0)