Revert "Use multiprocessing instead of os.fork()"

This reverts commit 1ec7c6c76a.
pull/136/head
ashfinal 5 years ago
parent 1ec7c6c76a
commit fe7979d9c5

@ -23,7 +23,6 @@ THE SOFTWARE.
"""
import argparse
import multiprocessing
import os
import re
import sys
@ -55,18 +54,7 @@ class Nvr():
# Ignore invalid addresses.
pass
def try_attach(self, args, nvr, options, arguments):
for i in range(10):
self.attach()
if self.server:
self.started_new_process = True
return main2(nvr, options, arguments)
time.sleep(0.2)
print('[!] Unable to attach to the new nvim process. Is `{}` working?'
.format(" ".join(args)))
sys.exit(1)
def execute_new_nvim_process(self, silent, nvr, options, arguments):
def start_new_process(self, silent):
if not silent:
print(textwrap.dedent('''\
[*] Starting new nvim process using $NVR_CMD or 'nvim'.
@ -77,14 +65,25 @@ class Nvr():
args = os.environ.get('NVR_CMD')
args = args.split(' ') if args else ['nvim']
multiprocessing.Process(target=self.try_attach, args=(args, nvr, options, arguments)).start()
os.environ['NVIM_LISTEN_ADDRESS'] = self.address
try:
os.execvpe(args[0], args, os.environ)
except FileNotFoundError:
print("[!] Can't start new nvim process: '{}' is not in $PATH.".format(args[0]))
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)
def read_stdin_into_buffer(self, cmd):
self.server.command(cmd)
@ -419,12 +418,11 @@ def main(argv=sys.argv, env=os.environ):
show_message(address)
if options.nostart:
sys.exit(1)
nvr.execute_new_nvim_process(silent, nvr, options, arguments)
main2(nvr, options, arguments)
nvr.start_new_process(silent)
if not nvr.server:
raise RuntimeError('This should never happen. Please raise an issue at https://github.com/mhinz/neovim-remote/issues')
def main2(nvr, options, arguments):
if options.d:
nvr.diffmode = True

Loading…
Cancel
Save