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

stderr.get_output() blocks #19

Open
jedie opened this issue Mar 3, 2019 · 2 comments
Open

stderr.get_output() blocks #19

jedie opened this issue Mar 3, 2019 · 2 comments

Comments

@jedie
Copy link

jedie commented Mar 3, 2019

  • ProcRunner version: 0.9.1
  • Python version: 3.6.7
  • Operating System: ubuntu

Description

I call adb kill-server, the process ends with exit code 0 but stderr.get_output() blocks.

What I Did

DEBUG:procrunner:Starting external process: ('adb', 'kill-server')
DEBUG:procrunner:Process ended after 0.0 seconds with exit code 0 (T-10.00s)* server not running *
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.6/tkinter/__init__.py", line 1705, in __call__
    return self.func(*args)
  File "/usr/lib/python3.6/tkinter/__init__.py", line 749, in callit
    func(*args)
  File "/home/jens/repos/PyAdbUninstall/adb_uninstall/gui.py", line 341, in reconnect
    self.subprocess("adb", "kill-server")
  File "/home/jens/repos/PyAdbUninstall/adb_uninstall/gui.py", line 309, in subprocess
    args, timeout=timeout, callback_stdout=callback_stdout, callback_stderr=callback_stderr
  File "/home/jens/repos/PyAdbUninstall/.virtualenv/lib/python3.6/site-packages/procrunner/__init__.py", line 492, in run
    stderr = stderr.get_output()

  File "/home/jens/repos/PyAdbUninstall/.virtualenv/lib/python3.6/site-packages/procrunner/__init__.py", line 176, in get_output
    self._thread.join()
  File "/usr/lib/python3.6/threading.py", line 1056, in join
    self._wait_for_tstate_lock()
  File "/usr/lib/python3.6/threading.py", line 1072, in _wait_for_tstate_lock
    elif lock.acquire(block, timeout):
KeyboardInterrupt
jedie added a commit to jedie/PyAdbUninstall that referenced this issue Mar 3, 2019
Anthchirp added a commit that referenced this issue Mar 3, 2019
There may be cases where the stream reader can not finish even though
the subprocess has already terminated. For example the subprocess can
pass the stdout/stderr handles on to a daemon process which will keep
them open. In those cases we need to stop reading at some point to
continue the normal control flow.

Proposed solution: wait for 1 second for the stream reader to catch up,
and if the stream is still held open or the stream reader is still
running ignore any further output and continue.

Downside: this is essentially a memory leak as the stream reader thread
may still linger on. To limit the potential damage add a check for the
._closed property in the main stream reader loop and terminate there.

Attempt at resolving #19.
Anthchirp added a commit that referenced this issue Mar 3, 2019
There may be cases where the stream reader can not finish even though
the subprocess has already terminated. For example the subprocess can
pass the stdout/stderr handles on to a daemon process which will keep
them open. In those cases we need to stop reading at some point to
continue the normal control flow.

Proposed solution: wait for 1 second for the stream reader to catch up,
and if the stream is still held open or the stream reader is still
running ignore any further output and continue.

Downside: this is essentially a memory leak as the stream reader thread
may still linger on. To limit the potential damage add a check for the
._closed property in the main stream reader loop and terminate there.

Might resolve #19.
@Anthchirp
Copy link
Contributor

Could you have a look at bb71233 and see if that fixes it for you?

@jedie
Copy link
Author

jedie commented Mar 3, 2019

Hm. No it still hangs...

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

2 participants