tools/litex_term: revert LiteXTerm to threading (multiprocessing breaks Windows/OS-X).

Ideally we should switch to AsyncIO as some point.
This commit is contained in:
Florent Kermarrec 2021-01-11 19:29:15 +01:00
parent 1ce194007b
commit 460fada3ac
1 changed files with 18 additions and 16 deletions

View File

@ -13,6 +13,7 @@ import signal
import os import os
import time import time
import serial import serial
import threading
import multiprocessing import multiprocessing
import argparse import argparse
import json import json
@ -271,6 +272,8 @@ class LiteXTerm:
sigint_time_current = time.time() sigint_time_current = time.time()
# Exit term if 2 CTRL-C pressed in less than 0.5s. # Exit term if 2 CTRL-C pressed in less than 0.5s.
if (sigint_time_current - self.sigint_time_last < 0.5): if (sigint_time_current - self.sigint_time_last < 0.5):
self.console.unconfigure()
self.close()
sys.exit() sys.exit()
else: else:
self.sigint_time_last = sigint_time_current self.sigint_time_last = sigint_time_current
@ -426,12 +429,13 @@ class LiteXTerm:
def start_reader(self): def start_reader(self):
self.reader_alive = True self.reader_alive = True
self.reader_thread = multiprocessing.Process(target=self.reader) self.reader_thread = threading.Thread(target=self.reader)
self.reader_thread.setDaemon(True)
self.reader_thread.start() self.reader_thread.start()
def stop_reader(self): def stop_reader(self):
self.reader_alive = False self.reader_alive = False
self.reader_thread.terminate() self.reader_thread.join()
def writer(self): def writer(self):
try: try:
@ -450,20 +454,26 @@ class LiteXTerm:
def start_writer(self): def start_writer(self):
self.writer_alive = True self.writer_alive = True
self.writer_thread = multiprocessing.Process(target=self.writer) self.writer_thread = threading.Thread(target=self.writer)
self.writer_thread.setDaemon(True)
self.writer_thread.start() self.writer_thread.start()
def stop_writer(self): def stop_writer(self):
self.writer_alive = False self.writer_alive = False
self.writer_thread.terminate() self.writer_thread.join()
def start(self): def start(self):
self.start_reader() self.start_reader()
self.start_writer() self.start_writer()
def stop(self): def stop(self):
self.reader_thread.terminate() self.reader_alive = False
self.writer_thread.terminate() self.writer_alive = False
def join(self, writer_only=False):
self.writer_thread.join()
if not writer_only:
self.reader_thread.join()
# Run ---------------------------------------------------------------------------------------------- # Run ----------------------------------------------------------------------------------------------
@ -494,16 +504,8 @@ def main():
port = args.port port = args.port
term.open(port, int(float(args.speed))) term.open(port, int(float(args.speed)))
term.console.configure() term.console.configure()
try:
term.start() term.start()
while True: term.join(True)
time.sleep(0.1)
except:
if bridge_cls is not None:
bridge.close()
term.console.unconfigure()
term.stop()
term.close()
if __name__ == "__main__": if __name__ == "__main__":
main() main()