Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invisible prompt in interactive mode #5

Open
perrette opened this issue Mar 1, 2013 · 6 comments
Open

invisible prompt in interactive mode #5

perrette opened this issue Mar 1, 2013 · 6 comments

Comments

@perrette
Copy link

perrette commented Mar 1, 2013

Hi, first of all many thanks for sharing this project, a really great idea, especially useful when trying to switch from matlab to python but still having many old routines in matlab.
I just had a go, everything went smoothly until I entered mlab.start()
Then I cannot see my input commands any more (nothing that I type appear at the screen, just the error messages). Even after I quit (i)python, the terminal remains unusable.
The test.py example runs smoothly though. Any idea where that could come from?

@jaderberg
Copy link
Owner

So are you using a python prompt when you get this problem?
If you are using ipython I highly recommend looking at the fork @arokem has been developing here https://github.com/arokem/python-matlab-bridge - it is a more mature and might help your problem.

@perrette
Copy link
Author

perrette commented Mar 1, 2013

Thanks for the prompt answer. I have just tried it out. Unfortunately it does not solve the problem. The end use is for scripting anyway, so it is not critical. But of course, ipython speeds up the development process considerably...

@arokem
Copy link

arokem commented Mar 1, 2013

Hi Mahe - thanks for trying this out and for reporting your difficulties!

What OS are you working on? You mentioned that you get errors emitted to
the Terminal. Could you please tell us what the errors were?

On Fri, Mar 1, 2013 at 10:43 AM, Mahé Perrette notifications@github.comwrote:

Thanks for the prompt answer. I have just tried it out. Unfortunately it
does not solve the problem. The end use is for scripting anyway, so it is
not critical. But of course, ipython speeds up the development process
considerably...


Reply to this email directly or view it on GitHubhttps://github.com//issues/5#issuecomment-14304422
.

@perrette
Copy link
Author

perrette commented Mar 2, 2013

Hi Arokem,

thanks for your answer. I am using Ubuntu 12.04. The terminal is from Xfce (XUbuntu). I have just checked the bug occurs with GNOME Terminal, too. Maybe something to do with log files / redirection of sys.stdout/in?

On a real use situation I have a more serious bug though. I print below the terminal output, maybe you have an idea what could be happening. It seems to be happening at the time of returning the output. By the way, the matlab function I call returns a structure. I am not sure how the structures are handled in pymatbridge - if at all. Anyway, here is the log (is there any better way with github to upload log files?):

"""
In [1]: run -i execute_from_python.py
Starting MATLAB on http://localhost:60091
visit http://localhost:60091/exit.m to shut down same
..Warning: No window system found. Java option 'MWT' ignored

                        < M A T L A B (R) >

"""

[etc.... everything going well so far...then it goes on with prints out, until]

"""


timeout Traceback (most recent call last)
/usr/local/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
176 else:
177 filename = fname
--> 178 builtin.execfile(filename, *where)

/home/perrette/Projects/SLR_Regional/gitSource/execute_from_python.py in ()
16 return res
17
---> 18 res = getit('Global_Projections/slr_global.m')
19 #res = getit('Global_Projections/slr_regional.m')

/home/perrette/Projects/SLR_Regional/gitSource/execute_from_python.py in getit(path2func, argdict)
8 mlab = Matlab(matlab='/usr/local/matlab/R2010a/bin/matlab')
9 mlab.start()
---> 10 mlab.run_func(path2func, argdict)
11 mlab.stop()
12 # try:

/usr/local/lib/python2.7/site-packages/pymatbridge/pymatbridge.pyc in run_func(self, func_path, func_args, maxtime)
155 result = self._open_page(self.feval, page_args, maxtime)
156 else:
--> 157 result = self._open_page(self.feval, page_args)
158 return result
159

/usr/local/lib/python2.7/site-packages/pymatbridge/pymatbridge.pyc in _open_page(self, page_name, arguments, timeout)
193 page = urllib2.urlopen('%s/%s' % (self.server, page_name),
194 urllib.urlencode(arguments),
--> 195 timeout)
196
197 self.running = False

/usr/lib/python2.7/urllib2.pyc in urlopen(url, data, timeout)
124 if _opener is None:
125 _opener = build_opener()
--> 126 return _opener.open(url, data, timeout)
127
128 def install_opener(opener):

/usr/lib/python2.7/urllib2.pyc in open(self, fullurl, data, timeout)
398 req = meth(req)
399
--> 400 response = self._open(req, data)
401
402 # post-process response

/usr/lib/python2.7/urllib2.pyc in _open(self, req, data)
416 protocol = req.get_type()
417 result = self._call_chain(self.handle_open, protocol, protocol +
--> 418 '_open', req)
419 if result:
420 return result

/usr/lib/python2.7/urllib2.pyc in _call_chain(self, chain, kind, meth_name, _args)
376 func = getattr(handler, meth_name)
377
--> 378 result = func(_args)
379 if result is not None:
380 return result

/usr/lib/python2.7/urllib2.pyc in http_open(self, req)
1205
1206 def http_open(self, req):
-> 1207 return self.do_open(httplib.HTTPConnection, req)
1208
1209 http_request = AbstractHTTPHandler.do_request_

/usr/lib/python2.7/urllib2.pyc in do_open(self, http_class, req)
1178 else:
1179 try:
-> 1180 r = h.getresponse(buffering=True)
1181 except TypeError: # buffering kw not supported
1182 r = h.getresponse()

/usr/lib/python2.7/httplib.pyc in getresponse(self, buffering)
1028 response = self.response_class(_args, *_kwds)
1029
-> 1030 response.begin()
1031 assert response.will_close != _UNKNOWN
1032 self.__state = _CS_IDLE

/usr/lib/python2.7/httplib.pyc in begin(self)
405 # read until we get a non-100 response
406 while True:
--> 407 version, status, reason = self._read_status()
408 if status != CONTINUE:
409 break

/usr/lib/python2.7/httplib.pyc in _read_status(self)
363 def _read_status(self):
364 # Initialize with Simple-Response defaults
--> 365 line = self.fp.readline()
366 if self.debuglevel > 0:
367 print "reply:", repr(line)

/usr/lib/python2.7/socket.pyc in readline(self, size)
445 while True:
446 try:
--> 447 data = self._sock.recv(self._rbufsize)
448 except error, e:
449 if e.args[0] == EINTR:

timeout: timed out
"""

That's it...Or can the structure simply not be returned?
[I'd imagine a natural way would be a dictionary of dictionaries? Although scipy.io.loadmat uses numpy array of the object type, in a rather weird way I find].

EDIT: the structure is quite large, maybe it has something to do with that

EDIT2: I have tried with a smaller structure, the output is fine, pymatbridge closes correctly. Maybe you have an idea which python / pymatbridge settings to change to avoid the error with large structures? The returned output, if saved to a matlab .mat file, is 104 Mb ...

Many thanks again.

@perrette
Copy link
Author

perrette commented Mar 2, 2013

Sorry, I did not answer your question on the printout bug. I meant I can see the error messages (and more generally the outputs) where there are some, but no error message specifically associated with the absence of prompt. For example, after executing the function in my example below, typing: "enter" then "2+2" , "2+3" then "ii", only the outputs and errors are shown, not the inputs:

In [9]:
In [10]: Out[10]: 4

In [11]: Out[11]: 5

In [12]: ---------------------------------------------------------------------------
NameError Traceback (most recent call last)
in ()
----> 1 ii

NameError: name 'ii' is not defined

In [13]:

EDIT: if pymatbridge executes matlab without errors and closes, there is not such bug. To handöe errors, I have tried with a try / except statement to always execute mlab.close(), but this fails (matlab seems to be closed anyway in case of errors), and the prompt bug remains.

@arokem
Copy link

arokem commented Mar 5, 2013

Just to be sure - did you try to run the example ipython notebooks that are
part of the source distribution? Do those work for you?

As for your use-case: one possibility is that the computation simply takes
longer than the defined maxtime (I just noticed that the documentation
doesn't say this, but it is limited to 10 seconds) and that's why you get
the timeout error

You can set the maxtime by starting your Matlab class with a key-word
argument as follows:

matlab = pymatbridge.Matlab(maxtime=100)

As for the Matlab struct - to be honest, I am not sure what will happen
with it. For the time being, it doesn't seem to be crashing on that. Let's
first see what happens when you give it more time.

On Sat, Mar 2, 2013 at 5:10 AM, Mahé Perrette notifications@github.comwrote:

Sorry, I did not answer your question on the printout bug. I meant I can
see the error messages (and more generally the outputs) where there are
some, but no error message specifically associated with the absence of
prompt. For example, after executing the function in my example below,
typing: then , then :

In [9]:
In [10]: Out[10]: 4

In [11]: Out[11]: 5

In [12]:

NameError Traceback (most recent call last)
in ()
----> 1 ii

NameError: name 'ii' is not defined

In [13]:


Reply to this email directly or view it on GitHubhttps://github.com//issues/5#issuecomment-14327988
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants