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

Error getting subprocess error with non-blocking mode #54

Open
jakul opened this issue Apr 27, 2018 · 6 comments
Open

Error getting subprocess error with non-blocking mode #54

jakul opened this issue Apr 27, 2018 · 6 comments

Comments

@jakul
Copy link

jakul commented Apr 27, 2018

Accessing command.err a second time causes an exception

In [1]: import delegator

In [2]: command = delegator.run('echo a', block=False)

In [3]: command.err
Out[3]: 'a\n'

In [4]: command.err
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-5e568e65e1e2> in <module>()
----> 1 command.err

~/.virtualenvs/service-mailer/lib/python3.6/site-packages/delegator.py in err(self)
    114             return self.__err
    115         else:
--> 116             return self._pexpect_out
    117
    118     @property

~/.virtualenvs/service-mailer/lib/python3.6/site-packages/delegator.py in _pexpect_out(self)
     82             result += self.subprocess.before
     83         if self.subprocess.after:
---> 84             result += self.subprocess.after
     85
     86         result += self.subprocess.read()

TypeError: must be str, not type

The cause is that self.subprocess.after becomes <class 'pexpect.exceptions.EOF'> after the first command.err

@jakul jakul changed the title Error getting subprocess error with Pexpect Error getting subprocess error with non-blocking mode Apr 27, 2018
@jakul
Copy link
Author

jakul commented Apr 27, 2018

I've just checked the docs and found out that I shouldn't use command.err with non-blocking mode. Maybe the correct fix for this bug it so update the err function to not even try to read the error streams in non-blocking mode?

@ParthS007
Copy link

Closing due to inactivity 👍

@timofurrer
Copy link
Contributor

timofurrer commented Feb 14, 2019

I'm re-opening this because there is actually a PR for it.

@jakul I think #62 fixed your issue, too. Can you please double check?

@timofurrer timofurrer reopened this Feb 14, 2019
@jakul
Copy link
Author

jakul commented Feb 14, 2019

@timofurrer The behaviour is better, but still not correct.

In [1]: import delegator

In [2]: command = delegator.run('echo a', block=False)

In [3]: command.err
Out[3]: 'a\n'

In [4]: command.err
Out[4]: 'a\n'

In [5]: command.err
Out[5]: ''

In [6]: command.err
Out[6]: ''

Now command.err has a different the first and second times I call it, compared to the 3rd, 4th etc.

@timofurrer
Copy link
Contributor

It's any ways strange that you get an output at all for command.err.
It seems to work fine when you try to get the stdout from command.out.

@timofurrer
Copy link
Contributor

I've just commited ad67b14 with which command.err is cached properly, but doesn't actually return stderr but stdout (which was already the case before this change. I'll have a look at how to change that behavior, too)

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