Restore original standard streams for device monitor // Issue #3939

This commit is contained in:
Ivan Kravets
2022-06-13 20:19:09 +03:00
parent 4b5bc91abb
commit 854c549e1c
2 changed files with 11 additions and 1 deletions

View File

@ -130,7 +130,6 @@ def device_monitor_cmd(**options):
"--exit-char can not be the same as --menu-char"
)
print(options)
start_terminal(options)

View File

@ -13,6 +13,7 @@
# limitations under the License.
import signal
import sys
import threading
import click
@ -60,8 +61,17 @@ def start_terminal(options):
except KeyboardInterrupt:
pass
term.join()
# cleanup
term.console.cleanup()
# restore original standard streams
sys.stdin = sys.__stdin__
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
term.close()
if term.pio_unexpected_exception:
click.secho(
"Disconnected (%s)" % term.pio_unexpected_exception,
@ -70,6 +80,7 @@ def start_terminal(options):
)
if not options["no_reconnect"]:
raise UserSideException(term.pio_unexpected_exception)
return
except UserSideException as exc:
if not is_port_valid: