Replace current process in another interpreter

pull/155/head
ashfinal 5 years ago
parent 5c437d87ca
commit a66fc40aa5

@ -23,6 +23,7 @@ THE SOFTWARE.
"""
import argparse
import multiprocessing
import os
import re
import sys
@ -54,6 +55,15 @@ class Nvr():
# Ignore invalid addresses.
pass
def exec_nvr_cmd(self, args):
os.environ['NVIM_LISTEN_ADDRESS'] = self.address
args = args.split(' ')
try:
os.execvpe(args[0], args, os.environ)
except FileNotFoundError:
print("[!] Can't start new nvim process: '{}' is not in $PATH.".format(args[0]))
sys.exit(1)
def start_new_process(self, silent):
if not silent:
print(textwrap.dedent('''\
@ -62,28 +72,18 @@ class Nvr():
Use --nostart to avoid starting a new process.
'''))
args = os.environ.get('NVR_CMD')
args = args.split(' ') if args else ['nvim']
pid = os.fork()
if pid == 0:
for i in range(10):
self.attach()
if self.server:
self.started_new_process = True
return True
time.sleep(0.2)
print('[!] Unable to attach to the new nvim process. Is `{}` working?'
.format(" ".join(args)))
sys.exit(1)
else:
os.environ['NVIM_LISTEN_ADDRESS'] = self.address
try:
os.dup2(sys.stdout.fileno(), sys.stdin.fileno())
os.execvpe(args[0], args, os.environ)
except FileNotFoundError:
print("[!] Can't start new nvim process: '{}' is not in $PATH.".format(args[0]))
sys.exit(1)
args = os.environ.get('NVR_CMD') or 'nvim'
multiprocessing.Process(target=self.exec_nvr_cmd, args=(args,)).start()
for i in range(10):
self.attach()
if self.server:
self.started_new_process = True
return True
time.sleep(0.2)
print('[!] Unable to attach to the new nvim process. Is `{}` working?'
.format(" ".join(args)))
sys.exit(1)
def read_stdin_into_buffer(self, cmd):
self.server.command(cmd)
@ -566,4 +566,3 @@ def main(argv=sys.argv, env=os.environ):
if __name__ == '__main__':
main()

Loading…
Cancel
Save