Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c1e899

Browse files
committed
ENH: Allow setting the maximal time to wait for a response from Matlab.
In case you want to do something that takes more than 10 seconds to run.
1 parent a3a4401 commit 6c1e899

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pymatbridge/matlab_magic.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class MatlabMagics(Magics):
7373
"""
7474
def __init__(self, shell,
7575
matlab='matlab',
76+
maxtime=None,
7677
matlab_converter=matlab_converter,
7778
pyconverter=np.asarray,
7879
cache_display_data=False):
@@ -86,6 +87,10 @@ def __init__(self, shell,
8687
The system call to start a matlab session. Allows you to choose a
8788
particular version of matlab if you want
8889
90+
maxtime : float
91+
The maximal time to wait for responses for matlab (in seconds).
92+
Default: 10 seconds.
93+
8994
pyconverter : callable
9095
To be called on matlab variables returning into the ipython
9196
namespace
@@ -104,6 +109,8 @@ def __init__(self, shell,
104109

105110
self.Matlab = pymat.Matlab(matlab)
106111
self.Matlab.start()
112+
113+
self.maxtime = maxtime
107114

108115
self.pyconverter = pyconverter
109116
self.matlab_converter = matlab_converter
@@ -112,7 +119,7 @@ def eval(self, line):
112119
"""
113120
Parse and evaluate a single line of matlab
114121
"""
115-
run_dict = self.Matlab.run_code(line)
122+
run_dict = self.Matlab.run_code(line, maxtime=self.maxtime)
116123

117124
if run_dict['success'] == 'false':
118125
raise MatlabInterperterError(line, run_dict['content']['stdout'])

pymatbridge/pymatbridge.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Matlab(object):
2828
server_process = Process()
2929

3030
def __init__(self, matlab='matlab', host='localhost', port=None,
31-
id='python-matlab-bridge', log=False):
31+
id='python-matlab-bridge', log=False, maxtime=None):
3232
"""
3333
Initialize this thing.
3434
@@ -51,6 +51,10 @@ def __init__(self, matlab='matlab', host='localhost', port=None,
5151
5252
log : bool
5353
Whether to save a log file in some known location.
54+
55+
maxtime : float
56+
The maximal time to wait for a response from matlab (optional,
57+
Default is
5458
5559
"""
5660

@@ -70,6 +74,7 @@ def __init__(self, matlab='matlab', host='localhost', port=None,
7074
self.server = 'http://%s:%s' % (self.host, str(self.port))
7175
self.id = id
7276
self.log = log
77+
self.maxtime = maxtime
7378

7479
def start(self):
7580
def _run_matlab_server():

0 commit comments

Comments
 (0)