transplant icon indicating copy to clipboard operation
transplant copied to clipboard

Stdout is delayed?

Open tsdev opened this issue 6 years ago • 5 comments

When I run the following command the STDOUT from Matlab is not transferred:

S = {'a':1.0}
mlab.disp(S)

Strangely, I get the output later after running a few more commands.

tsdev avatar Jul 28 '17 06:07 tsdev

Interesting. I have looked at this a bit, but I can't find the problem. It seems that Matlab buffers some of its outputs, and only prints them to stdout on the next drawnow. This is unfortunate, but there doesn't seem to be anything transplant can do to fix this short of repeatedly calling drawnow.

bastibe avatar Aug 09 '17 08:08 bastibe

Thanks for looking into it. Strangely it only happens sporadically.

tsdev avatar Aug 09 '17 08:08 tsdev

I'll keep this open in case I stumble across a solution

bastibe avatar Aug 09 '17 09:08 bastibe

First, good job. It is working much better than the engine provided by Matlab . I am running Python 3.6 with Matlab 2018b and I just don't have any stdout at all. I post this here because I am pretty sure it is related.

I tried playing with your start reader function but nothing worked.

`def _start_reader(self): 

    """Starts an asynchronous reader that echos everything the remote says"""
    stdout = self.process.stdout
    def reader():
        """Echo what the remote says using print"""
        for line in iter(stdout.readline, bytes()):
            print(line.decode(), end='')
    Thread(target=reader, daemon=True).start()`

I tried the following and I am "getting in of thread" and never getting print('getting out of thread') and never 'getting line'

    `def reader():

        print('getting in of thread')
        """Echo what the remote says using print"""
        for line in iter(stdout.readline, bytes()):
            print('getting line')
            print(line.decode(), end='')
        print('getting out of thread')`

So I guess that stdout.readline is never returning anything. Hope it helps

bareil76-code avatar Jan 27 '20 20:01 bareil76-code

I'm assuming you are running Windows? Matlab simply does not write to stdout on Windows (as is noted in the README). Which is just sad, but there's nothing to be done about it as far as I know.

If you need to capture output, you can always make your function calls with evalc. Not pretty or elegant, but that always works.

bastibe avatar Jan 28 '20 14:01 bastibe