mirror of
https://github.com/clearml/wexpect-venv
synced 2025-02-12 15:50:42 +00:00
use generated random pipe_file_name instead of pid
The process pid is differs from the host and the child's point of view. See #26 for more details. This, random generated pipe_file_name, whill solve this issue.
This commit is contained in:
parent
c8977d8460
commit
850eece43b
@ -30,6 +30,9 @@ def main():
|
||||
parser.add_argument('--port', type=int, help=
|
||||
"If the console reader class is SpawnSocket, this option specifies the "
|
||||
"socket's port.", default=False)
|
||||
parser.add_argument('--pipe_file_name', type=str, help=
|
||||
"If the console reader class is SpawnPipe, this option specifies the "
|
||||
"pipe's name.", default=None)
|
||||
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
@ -48,7 +51,7 @@ def main():
|
||||
command = wexpect_util.join_args(args.command)
|
||||
|
||||
cons = conole_reader_class(
|
||||
path=command, host_pid=args.host_pid, codepage=args.codepage, port=args.port,
|
||||
path=command, host_pid=args.host_pid, codepage=args.codepage, port=args.port, pipe_file_name=args.pipe_file_name,
|
||||
window_size_x=args.window_size_x, window_size_y=args.window_size_y,
|
||||
buffer_size_x=args.buffer_size_x, buffer_size_y=args.buffer_size_y,
|
||||
local_echo=wexpect_util.str2bool(args.local_echo), interact=wexpect_util.str2bool(args.interact))
|
||||
|
@ -515,8 +515,12 @@ class ConsoleReaderPipe(ConsoleReaderBase):
|
||||
else:
|
||||
end_time = time.time() + timeout
|
||||
|
||||
pipe_name = 'wexpect_{}'.format(self.console_pid)
|
||||
pipe_full_path = r'\\.\pipe\{}'.format(pipe_name)
|
||||
try:
|
||||
self.pipe_name = kwargs['pipe_file_name']
|
||||
except KeyError:
|
||||
self.pipe_name = 'wexpect_{}'.format(self.console_pid)
|
||||
|
||||
pipe_full_path = r'\\.\pipe\{}'.format(self.pipe_name)
|
||||
logger.info('Start pipe server: %s', pipe_full_path)
|
||||
self.pipe = win32pipe.CreateNamedPipe(
|
||||
pipe_full_path,
|
||||
|
@ -30,6 +30,7 @@ from .wexpect_util import join_args
|
||||
from .wexpect_util import init_logger
|
||||
from .wexpect_util import EOF_CHAR
|
||||
from .wexpect_util import SIGNAL_CHARS
|
||||
from .wexpect_util import generate_id
|
||||
|
||||
logger = logging.getLogger('wexpect')
|
||||
|
||||
@ -870,7 +871,8 @@ class SpawnPipe(SpawnBase):
|
||||
**kwargs):
|
||||
self.pipe = None
|
||||
self.console_class_name = 'ConsoleReaderPipe'
|
||||
self.console_class_parameters = {}
|
||||
self.pipe_file_name = f'wexpect_{generate_id()}'
|
||||
self.console_class_parameters = {'pipe_file_name': self.pipe_file_name}
|
||||
|
||||
super().__init__(
|
||||
command=command, args=args, timeout=timeout, maxread=maxread,
|
||||
@ -889,8 +891,7 @@ class SpawnPipe(SpawnBase):
|
||||
else:
|
||||
end_time = time.time() + timeout
|
||||
|
||||
pipe_name = 'wexpect_{}'.format(self.console_pid)
|
||||
pipe_full_path = r'\\.\pipe\{}'.format(pipe_name)
|
||||
pipe_full_path = r'\\.\pipe\{}'.format(self.pipe_file_name)
|
||||
logger.debug(f'Trying to connect to pipe: {pipe_full_path}')
|
||||
while True:
|
||||
if end_time < time.time():
|
||||
|
@ -14,6 +14,8 @@ import sys
|
||||
import os
|
||||
import logging
|
||||
import signal
|
||||
import string
|
||||
import random
|
||||
|
||||
# platform does not define VEOF so assume CTRL-D
|
||||
EOF_CHAR = b'\x04'
|
||||
@ -27,7 +29,19 @@ SPAM = 5
|
||||
logging.addLevelName(SPAM, "SPAM")
|
||||
|
||||
|
||||
def generate_id(size=6, chars=string.ascii_uppercase + string.digits):
|
||||
'''Generates random string, to use as ID.
|
||||
Using random string as pipe's filename gives a workaround to #26
|
||||
From: https://stackoverflow.com/a/2257449/2506522
|
||||
'''
|
||||
return ''.join(random.choice(chars) for _ in range(size))
|
||||
|
||||
|
||||
def str2bool(v):
|
||||
'''Help parsing boolean values with argparse
|
||||
From: https://stackoverflow.com/a/43357954/2506522
|
||||
|
||||
'''
|
||||
if isinstance(v, bool):
|
||||
return v
|
||||
if v.lower() in ('yes', 'true', 't', 'y', '1'):
|
||||
|
Loading…
Reference in New Issue
Block a user