@@ -453,6 +453,56 @@ def handler():
453
453
raise
454
454
self ._session .threadsafe_call (handler )
455
455
456
+ if IS_PYTHON3 :
457
+
458
+ def run_coroutine (self , coroutine ):
459
+ """ Run a coroutine inside a response handler (or setup_cb)"""
460
+
461
+ return self ._session .run_coroutine (coroutine )
462
+
463
+ def start_subprocess (self , cmd , on_data , on_exit , ** args ):
464
+ coro = self .loop .subprocess_exec (partial (NvimAsyncioProcess , self , on_data , on_exit ),
465
+ * cmd , ** args )
466
+ (transport , protocol ) = self .run_coroutine (coro )
467
+ return transport
468
+
469
+ if IS_PYTHON3 :
470
+
471
+ import asyncio
472
+
473
+
474
+ class NvimAsyncioProcess (asyncio .SubprocessProtocol ):
475
+
476
+ def __init__ (self , session , on_data , on_exit ):
477
+ self .session = session
478
+ self .on_data = on_data
479
+ self .on_exit = on_exit
480
+
481
+ self .call_point = '' .join (format_stack (None , 6 )[:- 2 ])
482
+
483
+ def _callback (self , cb , * args ):
484
+
485
+ def handler ():
486
+ try :
487
+ cb (* args )
488
+ except Exception as err :
489
+ msg = ("error caught while executing subprocess callback:\n "
490
+ "{!r}\n {}\n \n the process was created at\n {}"
491
+ .format (err , format_exc_skip (1 ), self .call_point ))
492
+ self .session ._err_cb (msg )
493
+ raise
494
+
495
+ self .session ._session .threadsafe_call (handler )
496
+
497
+
498
+ def connection_made (self , transport ):
499
+ pass
500
+
501
+ def pipe_data_received (self , fd , data ):
502
+ self ._callback (self .on_data , fd , data )
503
+
504
+ def process_exited (self ):
505
+ self ._callback (self .on_exit )
456
506
457
507
class Buffers (object ):
458
508
0 commit comments