Skip to content

Commit 127d873

Browse files
committed
Merge pull request #6 from openearth/jack-tracker-unregister
added unregister to tracker client
2 parents 152314c + 4b05237 commit 127d873

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

mmi/mmi_client.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def initialize(self, configfile=None):
2020
"""
2121
Initialize the module
2222
"""
23-
23+
2424
method = "initialize"
25-
25+
2626
A = None
2727
metadata = {method : configfile}
2828

@@ -33,9 +33,9 @@ def finalize(self):
3333
"""
3434
Finalize the module
3535
"""
36-
36+
3737
method = "finalize"
38-
38+
3939
A = None
4040
metadata = {method : -1}
4141

@@ -48,7 +48,7 @@ def get_var_count(self):
4848
"""
4949

5050
method = "get_var_count"
51-
51+
5252
A = None
5353
metadata = {method : -1}
5454

@@ -63,7 +63,7 @@ def get_var_name(self, i):
6363
"""
6464

6565
method = "get_var_name"
66-
66+
6767
A = None
6868
metadata = {method : i}
6969

@@ -78,7 +78,7 @@ def get_var_type(self, name):
7878
"""
7979

8080
method = "get_var_type"
81-
81+
8282
A = None
8383
metadata = {method : name}
8484

@@ -93,7 +93,7 @@ def get_var_rank(self, name):
9393
"""
9494

9595
method = "get_var_rank"
96-
96+
9797
A = None
9898
metadata = {method : name}
9999

@@ -108,7 +108,7 @@ def get_var_shape(self, name):
108108
"""
109109

110110
method = "get_var_shape"
111-
111+
112112
A = None
113113
metadata = {method : rank}
114114

@@ -123,7 +123,7 @@ def get_var(self, name):
123123
"""
124124

125125
method = "get_var"
126-
126+
127127
A = None
128128
metadata = {method : name}
129129

@@ -151,7 +151,7 @@ def get_start_time(self):
151151
"""
152152

153153
method = "get_start_time"
154-
154+
155155
A = None
156156
metadata = {method : -1}
157157

@@ -166,7 +166,7 @@ def get_end_time(self):
166166
"""
167167

168168
method = "get_end_time"
169-
169+
170170
A = None
171171
metadata = {method : -1}
172172

@@ -181,7 +181,7 @@ def get_current_time(self):
181181
"""
182182

183183
method = "get_current_time"
184-
184+
185185
A = None
186186
metadata = {method : -1}
187187

@@ -214,4 +214,19 @@ def inq_compound_field(self, name, index):
214214
"""
215215
Lookup the type,rank and shape of a compound field
216216
"""
217-
pass
217+
pass
218+
219+
def remote(self, action):
220+
"""
221+
Function specific for MMI, not BMI.
222+
action is one of: "play", "stop", "pause", "rewind", "quit"
223+
"""
224+
method = "remote"
225+
226+
A = None
227+
metadata = {method: action}
228+
229+
send_array(self.socket, A, metadata)
230+
A, metadata = recv_array(self.socket)
231+
232+
return metadata[method]

mmi/runner.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ def process_incoming(model, sockets, data):
9797
var = model.get_var(name).copy()
9898
else:
9999
var = model.get_var(name)
100-
logger.debug("sending variable %s with shape %s", name, var.shape)
100+
if var is None:
101+
logger.warning("Get_var returns None for %s" % name)
102+
else:
103+
logger.debug("sending variable %s with shape %s", name, var.shape)
101104
metadata['name'] = name
102105
# assert socket is req socket
103106

@@ -171,7 +174,8 @@ def process_incoming(model, sockets, data):
171174
# assert socket is req socket
172175
# custom actions
173176
elif "remote" in metadata:
174-
assert metadata["remote"] in {"play", "stop", "pause", "rewind"}
177+
assert metadata["remote"] in {
178+
"play", "stop", "pause", "rewind", "quit"}
175179
model.state = metadata["remote"]
176180
elif "operator" in metadata:
177181
# TODO: support same operators as MPI_ops here....,
@@ -360,15 +364,16 @@ def runner(
360364

361365
# Keep on counting indefinitely
362366
counter = itertools.count()
363-
367+
logger.info("Entering timeloop...")
364368
for i in counter:
365369
while model.state == "pause":
366370
# keep waiting for messages when paused
367371
process_incoming(model, sockets, data)
368372
else:
369373
# otherwise process messages once and continue
370374
process_incoming(model, sockets, data)
371-
logger.debug("i %s", i)
375+
if model.state == "quit":
376+
break
372377

373378
# paused ...
374379
model.update(-1)
@@ -385,6 +390,8 @@ def runner(
385390
if 'pub' in sockets:
386391
send_array(sockets['pub'], value, metadata=metadata)
387392

393+
logger.info("Exiting...")
394+
388395

389396
def main():
390397
arguments = docopt.docopt(__doc__)

mmi/tracker_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import urllib2
22
import json
3+
import requests
4+
import urlparse
35

46

57
class MMITracker(object):
@@ -35,3 +37,8 @@ def zmq_address(self, key):
3537
"""
3638
zmq_address = "tcp://" + self.database[key]['node'] + ":" + str(self.database[key]['ports']['REQ'])
3739
return zmq_address
40+
41+
def unregister(self, uuid):
42+
"""Unregister a uuid from tracker"""
43+
requests.delete(
44+
urlparse.urljoin(self.tracker_url, 'models' + "/" + uuid))

0 commit comments

Comments
 (0)