@@ -60,7 +60,7 @@ def read_until(self, min_num_bytes, ending, timeout=10, data_consumer=None):
6060 timeout_count = 0
6161 else :
6262 timeout_count += 1
63- if timeout_count >= 10 * timeout :
63+ if timeout is not None and timeout_count >= 10 * timeout :
6464 break
6565 time .sleep (0.1 )
6666 return data
@@ -81,23 +81,23 @@ def enter_raw_repl(self):
8181 def exit_raw_repl (self ):
8282 self .serial .write (b'\r \x02 ' ) # ctrl-B: enter friendly REPL
8383
84- def follow (self , data_consumer = False ):
84+ def follow (self , timeout , data_consumer = None ):
8585 # wait for normal output
86- data = self .read_until (1 , b'\x04 ' , data_consumer = data_consumer )
86+ data = self .read_until (1 , b'\x04 ' , timeout = timeout , data_consumer = data_consumer )
8787 if not data .endswith (b'\x04 ' ):
8888 raise PyboardError ('timeout waiting for first EOF reception' )
8989 data = data [:- 1 ]
9090
9191 # wait for error output
92- data_err = self .read_until (2 , b'\x04 >' )
92+ data_err = self .read_until (2 , b'\x04 >' , timeout = timeout )
9393 if not data_err .endswith (b'\x04 >' ):
9494 raise PyboardError ('timeout waiting for second EOF reception' )
9595 data_err = data_err [:- 2 ]
9696
9797 # return normal and error output
9898 return data , data_err
9999
100- def exec_raw (self , command , data_consumer = False ):
100+ def exec_raw (self , command , timeout = 10 , data_consumer = None ):
101101 if isinstance (command , bytes ):
102102 command_bytes = command
103103 else :
@@ -114,7 +114,7 @@ def exec_raw(self, command, data_consumer=False):
114114 if data != b'OK' :
115115 raise PyboardError ('could not exec command' )
116116
117- return self .follow (data_consumer )
117+ return self .follow (timeout , data_consumer )
118118
119119 def eval (self , expression ):
120120 ret = self .exec ('print({})' .format (expression ))
@@ -214,7 +214,7 @@ def main():
214214 if len (args .files ) == 0 :
215215 try :
216216 pyb = Pyboard (args .device )
217- ret , ret_err = pyb .follow (data_consumer = lambda d :print (str (d , encoding = 'ascii' ), end = '' ))
217+ ret , ret_err = pyb .follow (timeout = None , data_consumer = lambda d :print (str (d , encoding = 'ascii' ), end = '' ))
218218 pyb .close ()
219219 except PyboardError as er :
220220 print (er )
@@ -231,7 +231,7 @@ def main():
231231 pyb .enter_raw_repl ()
232232 with open (filename ) as f :
233233 pyfile = f .read ()
234- ret , ret_err = pyb .exec_raw (pyfile , data_consumer = lambda d :print (str (d , encoding = 'ascii' ), end = '' ))
234+ ret , ret_err = pyb .exec_raw (pyfile , timeout = None , data_consumer = lambda d :print (str (d , encoding = 'ascii' ), end = '' ))
235235 pyb .exit_raw_repl ()
236236 pyb .close ()
237237 except PyboardError as er :
0 commit comments