Skip to content

Commit

Permalink
Merge pull request #82 from BrianPugh/exit-raw-repl-on-close
Browse files Browse the repository at this point in the history
exit_raw_repl() on close
  • Loading branch information
BrianPugh authored Jan 30, 2023
2 parents 0c9f8a1 + 08db9c6 commit cd876aa
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions belay/pyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,15 @@ def process_output():
thread.start()

time.sleep(5.0) # Give process a chance to boot up.
if platform.system() == "Windows":
# Windows needs more time
time.sleep(5.0)

def cleanup():
_kill_process(subp.pid)

atexit.register(cleanup)
atexit.register(self.close)

def close(self):
_kill_process(self.subp.pid)
atexit.unregister(self.close)

def read(self, size=1):
while len(self.buf) < size:
Expand Down Expand Up @@ -357,8 +358,15 @@ def __init__(

time.sleep(1.0)

atexit.register(self.close)

def close(self):
if not self.serial:
return
self.exit_raw_repl()
self.serial.close()
self.serial = None
atexit.unregister(self.close)

def read_until(self, min_num_bytes, ending, timeout=10, data_consumer=None):
"""
Expand Down

0 comments on commit cd876aa

Please sign in to comment.