@@ -453,6 +453,55 @@ def handler():
453
453
raise
454
454
self ._session .threadsafe_call (handler )
455
455
456
+ if IS_PYTHON3 :
457
+
458
+ def run_coro (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_coro (coro )
467
+
468
+ if IS_PYTHON3 :
469
+
470
+ import asyncio
471
+
472
+
473
+ class NvimAsyncioProcess (asyncio .SubprocessProtocol ):
474
+
475
+ def __init__ (self , session , on_data , on_exit ):
476
+ self .session = session
477
+ self .on_data = on_data
478
+ self .on_exit = on_exit
479
+
480
+ self .call_point = '' .join (format_stack (None , 6 )[:- 2 ])
481
+
482
+ def _callback (self , cb , * args ):
483
+
484
+ def handler ():
485
+ try :
486
+ cb (* args )
487
+ except Exception as err :
488
+ msg = ("error caught while executing subprocess callback:\n "
489
+ "{!r}\n {}\n \n the process was created at\n {}"
490
+ .format (err , format_exc_skip (1 ), self .call_point ))
491
+ self .session ._err_cb (msg )
492
+ raise
493
+
494
+ self .session ._session .threadsafe_call (handler )
495
+
496
+
497
+ def connection_made (self , transport ):
498
+ pass
499
+
500
+ def pipe_data_received (self , fd , data ):
501
+ self ._callback (self .on_data , fd , data )
502
+
503
+ def process_exited (self ):
504
+ self ._callback (self .on_exit )
456
505
457
506
class Buffers (object ):
458
507
0 commit comments