@@ -379,7 +379,7 @@ def _close(self, exc=None):
379379        self ._remove_reader ()
380380        if  self ._flushed ():
381381            self ._remove_writer ()
382-             self ._loop .call_soon (self ._call_connection_lost ,  exc )
382+             self ._loop .create_task (self ._call_connection_lost ( exc ) )
383383
384384    def  _abort (self , exc ):
385385        """Close the transport immediately. 
@@ -393,9 +393,9 @@ def _abort(self, exc):
393393        self ._closing  =  True 
394394        self ._remove_reader ()
395395        self ._remove_writer ()  # Pending buffered data will not be written 
396-         self ._loop .call_soon (self ._call_connection_lost ,  exc )
396+         self ._loop .create_task (self ._call_connection_lost ( exc ) )
397397
398-     def  _call_connection_lost (self , exc ):
398+     async   def  _call_connection_lost (self , exc ):
399399        """Close the connection. 
400400
401401        Informs the protocol through connection_lost() and clears 
@@ -405,16 +405,17 @@ def _call_connection_lost(self, exc):
405405        assert  not  self ._has_writer 
406406        assert  not  self ._has_reader 
407407        try :
408-             self ._serial .flush ( )
408+             await   self ._loop . run_in_executor ( None ,  self . _serial .flush )
409409        except  (serial .SerialException  if  os .name  ==  "nt"  else  termios .error ):
410410            # ignore serial errors which may happen if the serial device was 
411411            # hot-unplugged. 
412412            pass 
413+ 
413414        try :
414415            self ._protocol .connection_lost (exc )
415416        finally :
416417            self ._write_buffer .clear ()
417-             self ._serial .close ( )
418+             await   self ._loop . run_in_executor ( None ,  self . _serial .close )
418419            self ._serial  =  None 
419420            self ._protocol  =  None 
420421            self ._loop  =  None 
@@ -445,7 +446,7 @@ async def create_serial_connection(loop, protocol_factory, *args, **kwargs):
445446
446447    Any additional arguments will be forwarded to the Serial constructor. 
447448    """ 
448-     serial_instance  =  serial .serial_for_url ( * args , ** kwargs )
449+     serial_instance  =  await   loop . run_in_executor ( None ,  serial .serial_for_url ,  * args , ** kwargs )
449450    transport , protocol  =  await  connection_for_serial (loop , protocol_factory , serial_instance )
450451    return  transport , protocol 
451452
0 commit comments