arokem / python-matlab-bridge

A simple Python => MATLAB(R) interface and a matlab_magic for ipython
BSD 2-Clause "Simplified" License
335 stars 96 forks source link

"Error writing to output stream" on alternating calls of `run_code()` #180

Closed neuromusic closed 9 years ago

neuromusic commented 9 years ago

my initial discovery of this issue is outlined at arokem/python-matlab-bridge#171 I suspect that this is the same problem as Calysto/matlab_kernel#8

Basically, I'm running pymatbridge from an iPython notebook server. The first Matlab() instance (or the first matlab_kernel that is created) returns "Error writing to output stream" on every other call

So the following code...

from pymatbridge import Matlab
mlab = Matlab()
mlab.start()
print mlab.run_code('a = [1,2,3,4]')
print mlab.run_code('a = [1,2,3,4]')
print mlab.run_code('a = [1,2,3,4]')
print mlab.run_code('a = [1,2,3,4]')

returns

{u'content': {u'datadir': u'/tmp/MatlabData/', u'code': u'a = [1,2,3,4]', u'figures': [], u'stdout': u'\na =\n\n     1     2     3     4\n\n'}, u'success': u'true'}
{u'content': {u'code': u'a = [1,2,3,4]', u'stdout': u'Error writing to output stream.\n\n'}, u'success': u'false'}
{u'content': {u'datadir': u'/tmp/MatlabData/', u'code': u'a = [1,2,3,4]', u'figures': [], u'stdout': u'\na =\n\n     1     2     3     4\n\n'}, u'success': u'true'}
{u'content': {u'code': u'a = [1,2,3,4]', u'stdout': u'Error writing to output stream.\n\n'}, u'success': u'false'}

Bizarro.

Also, the figures it returns are not formatted the same as subsequent instances. The are smaller and more pixelated.

arokem commented 9 years ago

I am not seeing this here. I suspect that you are running an installation of the last release? Would you mind updating to current master and giving it another try?

We should put out a release soon (I'm thinking Monday, unless someone has objections), so release installations should work as well, but we need feedback to see that things really are working on master.

On Mon, Apr 20, 2015 at 8:39 PM, Justin Kiggins notifications@github.com wrote:

my initial discovery of this issue is outlined at arokem/python-matlab-bridge#171 https://github.com/arokem/python-matlab-bridge/issues/171 I suspect that this is the same problem as Calysto/matlab_kernel#8 https://github.com/Calysto/matlab_kernel/issues/8

Basically, I'm running pymatbridge from an iPython notebook server. The first Matlab() instance (or the first matlab_kernel that is created) returns "Error writing to output stream" on every other call

So the following code...

from pymatbridge import Matlab mlab = Matlab() mlab.start()print mlab.run_code('a = [1,2,3,4]')print mlab.run_code('a = [1,2,3,4]')print mlab.run_code('a = [1,2,3,4]')print mlab.run_code('a = [1,2,3,4]')

returns

{u'content': {u'datadir': u'/tmp/MatlabData/', u'code': u'a = [1,2,3,4]', u'figures': [], u'stdout': u'\na =\n\n 1 2 3 4\n\n'}, u'success': u'true'} {u'content': {u'code': u'a = [1,2,3,4]', u'stdout': u'Error writing to output stream.\n\n'}, u'success': u'false'} {u'content': {u'datadir': u'/tmp/MatlabData/', u'code': u'a = [1,2,3,4]', u'figures': [], u'stdout': u'\na =\n\n 1 2 3 4\n\n'}, u'success': u'true'} {u'content': {u'code': u'a = [1,2,3,4]', u'stdout': u'Error writing to output stream.\n\n'}, u'success': u'false'}

Bizarro.

Also, the figures it returns are not formatted the same as subsequent instances. The are smaller and more pixelated.

— Reply to this email directly or view it on GitHub https://github.com/arokem/python-matlab-bridge/issues/180.

neuromusic commented 9 years ago

upgraded to master and now things have totally broken.

pymatbridge can't start matlab.

output after mlab.start()...

Starting MATLAB on ZMQ socket ipc:///tmp/pymatbridge
Send 'exit' command to kill the server
............................................................MATLAB session timed out after 60 seconds

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-ec1007d95844> in <module>()
      1 from pymatbridge import Matlab
      2 mlab = Matlab('/usr/local/MATLAB/R2015a/bin/matlab')
----> 3 mlab.start()

/usr/local/home/jkiggins/Code/python-matlab-bridge/pymatbridge/pymatbridge.py in start(self)
    216             return self
    217         else:
--> 218             raise ValueError("%s failed to start" % self._program_name())
    219 
    220     def _response(self, **kwargs):

ValueError: MATLAB failed to start

checking my ipython log...

[I 10:14:04.738 NotebookApp] Kernel started: 5d7d4e87-ef8e-47e0-9e8d-eb0bcfb13203
Invalid MEX-file
'/usr/local/home/jkiggins/Code/python-matlab-bridge/pymatbridge/matlab/messenger.mexa64':
/lib64/libc.so.6: version `GLIBC_2.17' not found (required by
/usr/local/home/jkiggins/Code/python-matlab-bridge/pymatbridge/matlab/messenger.mexa64)

Error in matlabserver (line 7)
messenger('init', socket_address);

FWIW, I installed from master with pip install -e ./

neuromusic commented 9 years ago

I'm on Scientific Linux 6 which is running glibc-2.12, which seems to be the problem.

Does the messenger really need 2.17?

arokem commented 9 years ago

Ugh. Sorry about this. I don't think we were anticipating this...

What are your thoughts, @aebrahim?

On Tue, Apr 21, 2015 at 10:37 AM, Justin Kiggins notifications@github.com wrote:

I'm on Scientific Linux 6 which is running glibc-2.12.

— Reply to this email directly or view it on GitHub https://github.com/arokem/python-matlab-bridge/issues/180#issuecomment-94881767 .

neuromusic commented 9 years ago

Even Ubuntu 12.04LTS (which is being maintained until April 2017) is on glibc-2.15

http://en.wikipedia.org/wiki/GNU_C_Library

aebrahim commented 9 years ago

Looking into this. If you build the mex yourself does it work?

neuromusic commented 9 years ago

@aebrahim nope. tried that :( at least I ran make.py and let it do its thing.

aebrahim commented 9 years ago

Did make.py succeed? If so, try running python setup.py install again. I can't think of a good reason for that to fail.

On Tue, Apr 21, 2015 at 11:52 AM, Justin Kiggins notifications@github.com wrote:

@aebrahim https://github.com/aebrahim nope. tried that :( at least I ran make.py and let it do its thing.

— Reply to this email directly or view it on GitHub https://github.com/arokem/python-matlab-bridge/issues/180#issuecomment-94903567 .

aebrahim commented 9 years ago

I believe @jjangsangy is planning to hook make.py into setup.py but for the time being they are still two separate steps.

On Tue, Apr 21, 2015 at 11:55 AM, Ali Ebrahim aebrahim@ucsd.edu wrote:

Did make.py succeed? If so, try running python setup.py install again. I can't think of a good reason for that to fail.

On Tue, Apr 21, 2015 at 11:52 AM, Justin Kiggins <notifications@github.com

wrote:

@aebrahim https://github.com/aebrahim nope. tried that :( at least I ran make.py and let it do its thing.

— Reply to this email directly or view it on GitHub https://github.com/arokem/python-matlab-bridge/issues/180#issuecomment-94903567 .

neuromusic commented 9 years ago

OK. make.py then another pip install worked. no more glib errors.

aaand...

the "Error writing to output stream" error is gone now that I'm on master.

Thanks for your help!!

mmagnuski commented 9 years ago

It says MATLAB session timed out after 60 seconds - I think I have had this. My matlab starts really slow and pymatbridge did not wait long enough. In my case it works if you try to connect again to matlab with the same socket address, does it work for you?

jjangsangy commented 9 years ago

Quick Update

Sorry about the late updates. Currently moving around and the nomadic lifestyle makes it difficult to get any real work done.

Changes

Likely I am thinking the merge for compilation and packaging will be very messy, since I'm starting to merge a lot of my branches on my end.

I will update a fork with the changes. I have a working copy that passes all unit tests, so people can start using that as very beta solution if the traditional make.py doesn't do the trick.

Setup

But ultimately the entire build and discovery process should be pretty seamless for unix systems running.

   # This will do the trick
    python setup.py build_ext --inline

For windows based builds, it's a little more complicated but the windows build will be able to benefit from all the changes mostly as long as the required MS VS C++ tools are installed.

jjangsangy commented 9 years ago

Okay I lied

Run

python setup.py messenger

Now builds the binary into the main root folder.

This is highly highly beta, I have really shocked it works.

screen shot 2015-04-22 at 9 38 27 am

jjangsangy commented 9 years ago

Also I forgot to mention, running

python setup.py test

Now runs the unit test suite.

screen shot 2015-04-22 at 9 45 46 am

arokem commented 9 years ago

Hey @jjangsangy - where is all this happening? Is this on one of your PRs? Or on a branch somewhere where I could take a look?

jjangsangy commented 9 years ago

Oh sorry, ya it's on this fork.

https://github.com/jjangsangy/python-matlab-bridge

arokem commented 9 years ago

It's on your master branch?

On Wed, Apr 22, 2015 at 11:34 AM, Sang Han notifications@github.com wrote:

Oh sorry, ya it's on this fork.

https://github.com/jjangsangy/python-matlab-bridge

— Reply to this email directly or view it on GitHub https://github.com/arokem/python-matlab-bridge/issues/180#issuecomment-95294388 .

jjangsangy commented 9 years ago

Yup, I got a little stuck trying to rebasing these commits together, but ran into too many conflicts.

I think it's likely that we'll just have to work through a merging strategy.

arokem commented 9 years ago

OK - I just tried a rebase - it's going to require some elbow grease. I can give it a go later this week, or maybe early next week, if you don't get to it before.

On Wed, Apr 22, 2015 at 11:44 AM, Sang Han notifications@github.com wrote:

Yup, I got a little stuck trying to rebasing these commits together, but ran into too many conflicts.

I think it's likely that we'll just have to work through a merge.

— Reply to this email directly or view it on GitHub https://github.com/arokem/python-matlab-bridge/issues/180#issuecomment-95297725 .

jjangsangy commented 9 years ago

Sure, I think my timeframe is similar. Now that we can compile using the setuptools machinery we can start deprecating components that are unnecessary and that will probably help make the transition a little easier.

I also don't mind explaining in details about how certain components work if that information is helpful as well!