Skip to content

Commit

Permalink
exit_server.m
Browse files Browse the repository at this point in the history
  • Loading branch information
jaderberg committed Apr 11, 2012
1 parent 2e4e2e5 commit e9a5e0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
13 changes: 8 additions & 5 deletions pymatbridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Part of Python-MATLAB-bridge
# Max Jaderberg 2012
###############################################
from httplib import BadStatusLine
import urllib2, urllib, os, json, time
from multiprocessing import Process

Expand Down Expand Up @@ -44,11 +45,13 @@ def _run_matlab_server():

def stop(self):
# Stop the MATLAB server
self.server_process.terminate()
self.server_process.join()
while self.server_process.is_alive():
time.sleep(0.25)
os.system('killall MATLAB')
try:
try:
resp = self._open_page('exit_server.m', {'id': self.id})
except BadStatusLine:
pass
except urllib2.URLError:
pass
print "MATLAB closed"
return True

Expand Down
3 changes: 3 additions & 0 deletions pymatbridge/matlab/www/exit_server.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function json_response = exit_server(headers, config)
exit;
json_response = '{}';
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pymatbridge import Matlab

# Initialise MATLAB
mlab = Matlab(port=5000)
mlab = Matlab(port=4000)
# Start the server
mlab.start()
# Run a test function: just adds 1 to the argument a
Expand Down

0 comments on commit e9a5e0d

Please sign in to comment.