-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathserver.py
56 lines (38 loc) · 1.16 KB
/
server.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
#!/usr/bin/python
import tensorflow as tf
cluster_spec = {'ps': ['localhost:2222'], 'worker': ['localhost:2223', 'localhost:2224']}
import socket
from flask import Flask
try:
from urllib2 import urlopen
from urllib import urlretrieve, quote
except ImportError:
from urllib.request import urlopen, urlretrieve, quote # py3 HELL
app = Flask(__name__)
@app.route('/')
def index():
return 'TensorPeers distributed training server!\n'
@app.route('/register')
def register():
return 'TensorPeers training client registered!\n'
@app.route('/list')
def list_clients():
return 'TensorPeers training client list:\n'+ client_list()
@app.route('/start')
def start():
print("waiting for clients")
cluster = tf.train.ClusterSpec(cluster_spec)
server = tf.train.Server(cluster, job_name="ps")
server.join()
return "waiting for clients"
def client_list():
return "\n".join(myip)
def download(url): # to memory
return urlopen(url).read()
host = socket.gethostname()
print("host", host)
myip = download('http://pannous.net/ip.php').strip()
print("myip", myip)
# local_ip=socket.gethostbyname(host)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=2221)