mirror of
https://github.com/clearml/wexpect-venv
synced 2025-03-04 02:57:38 +00:00
[FIX] isalive now uses flag_eof, and return false, if the eof has been catched
This commit is contained in:
parent
d46e700655
commit
3d65f30b16
@ -57,8 +57,7 @@ class IsAliveTestCase(PexpectTestCase.PexpectTestCase):
|
|||||||
def test_expect_isalive_dead_after_SIGHUP(self):
|
def test_expect_isalive_dead_after_SIGHUP(self):
|
||||||
p = wexpect.spawn('cat', timeout=5)
|
p = wexpect.spawn('cat', timeout=5)
|
||||||
assert p.isalive()
|
assert p.isalive()
|
||||||
force = False
|
self.assertTrue(p.terminate())
|
||||||
self.assertEqual(p.terminate(), True)
|
|
||||||
p.expect(wexpect.EOF)
|
p.expect(wexpect.EOF)
|
||||||
assert not p.isalive()
|
assert not p.isalive()
|
||||||
|
|
||||||
@ -77,7 +76,7 @@ class IsAliveTestCase(PexpectTestCase.PexpectTestCase):
|
|||||||
def test_expect_isalive_dead_after_SIGKILL(self):
|
def test_expect_isalive_dead_after_SIGKILL(self):
|
||||||
p = wexpect.spawn('cat', timeout=5)
|
p = wexpect.spawn('cat', timeout=5)
|
||||||
assert p.isalive()
|
assert p.isalive()
|
||||||
p.kill(9)
|
p.kill()
|
||||||
p.expect(wexpect.EOF)
|
p.expect(wexpect.EOF)
|
||||||
assert not p.isalive()
|
assert not p.isalive()
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ class ConsoleReaderBase:
|
|||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
self.terminate_child()
|
self.terminate_child()
|
||||||
time.sleep(.1)
|
time.sleep(.01)
|
||||||
self.send_to_host(self.readConsoleToCursor())
|
self.send_to_host(self.readConsoleToCursor())
|
||||||
self.sendeof()
|
self.sendeof()
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
|
@ -413,8 +413,11 @@ class SpawnBase:
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def isalive(self, console=True):
|
def isalive(self, trust_console=True):
|
||||||
"""True if the child is still alive, false otherwise"""
|
"""True if the child is still alive, false otherwise"""
|
||||||
|
if trust_console:
|
||||||
|
if self.flag_eof:
|
||||||
|
return False
|
||||||
|
|
||||||
if self.child_process is None:
|
if self.child_process is None:
|
||||||
# Child process has not been started... Not alive
|
# Child process has not been started... Not alive
|
||||||
@ -839,6 +842,8 @@ class SpawnPipe(SpawnBase):
|
|||||||
super().__init__(command=command, args=args, timeout=timeout, maxread=maxread,
|
super().__init__(command=command, args=args, timeout=timeout, maxread=maxread,
|
||||||
searchwindowsize=searchwindowsize, cwd=cwd, env=env, codepage=codepage, echo=echo, interact=interact)
|
searchwindowsize=searchwindowsize, cwd=cwd, env=env, codepage=codepage, echo=echo, interact=interact)
|
||||||
|
|
||||||
|
self.delayafterterminate = 1 # Sets delay in terminate() method to allow kernel time to update process status. Time in seconds.
|
||||||
|
|
||||||
def connect_to_child(self):
|
def connect_to_child(self):
|
||||||
pipe_name = 'wexpect_{}'.format(self.console_pid)
|
pipe_name = 'wexpect_{}'.format(self.console_pid)
|
||||||
pipe_full_path = r'\\.\pipe\{}'.format(pipe_name)
|
pipe_full_path = r'\\.\pipe\{}'.format(pipe_name)
|
||||||
@ -960,6 +965,8 @@ class SpawnSocket(SpawnBase):
|
|||||||
super().__init__(command=command, args=args, timeout=timeout, maxread=maxread,
|
super().__init__(command=command, args=args, timeout=timeout, maxread=maxread,
|
||||||
searchwindowsize=searchwindowsize, cwd=cwd, env=env, codepage=codepage, echo=echo, interact=interact)
|
searchwindowsize=searchwindowsize, cwd=cwd, env=env, codepage=codepage, echo=echo, interact=interact)
|
||||||
|
|
||||||
|
self.delayafterterminate = 1 # Sets delay in terminate() method to allow kernel time to update process status. Time in seconds.
|
||||||
|
|
||||||
def _send_impl(self, s):
|
def _send_impl(self, s):
|
||||||
"""This sends a string to the child process. This returns the number of
|
"""This sends a string to the child process. This returns the number of
|
||||||
bytes written. If a log file was set then the data is also written to
|
bytes written. If a log file was set then the data is also written to
|
||||||
|
Loading…
Reference in New Issue
Block a user