Skip to content

Commit

Permalink
Restore original standard streams for device monitor // Issue #3939
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankravets committed Jun 13, 2022
1 parent 4b5bc91 commit 854c549
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 0 additions & 1 deletion platformio/device/monitor/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def device_monitor_cmd(**options):
"--exit-char can not be the same as --menu-char"
)

print(options)
start_terminal(options)


Expand Down
11 changes: 11 additions & 0 deletions platformio/device/monitor/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import signal
import sys
import threading

import click
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down

0 comments on commit 854c549

Please sign in to comment.