mirror of
https://github.com/clearml/wexpect-venv
synced 2025-03-03 18:51:55 +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):
|
||||
p = wexpect.spawn('cat', timeout=5)
|
||||
assert p.isalive()
|
||||
force = False
|
||||
self.assertEqual(p.terminate(), True)
|
||||
self.assertTrue(p.terminate())
|
||||
p.expect(wexpect.EOF)
|
||||
assert not p.isalive()
|
||||
|
||||
@ -77,7 +76,7 @@ class IsAliveTestCase(PexpectTestCase.PexpectTestCase):
|
||||
def test_expect_isalive_dead_after_SIGKILL(self):
|
||||
p = wexpect.spawn('cat', timeout=5)
|
||||
assert p.isalive()
|
||||
p.kill(9)
|
||||
p.kill()
|
||||
p.expect(wexpect.EOF)
|
||||
assert not p.isalive()
|
||||
|
||||
|
@ -150,7 +150,7 @@ class ConsoleReaderBase:
|
||||
finally:
|
||||
try:
|
||||
self.terminate_child()
|
||||
time.sleep(.1)
|
||||
time.sleep(.01)
|
||||
self.send_to_host(self.readConsoleToCursor())
|
||||
self.sendeof()
|
||||
time.sleep(.1)
|
||||
|
@ -413,8 +413,11 @@ class SpawnBase:
|
||||
|
||||
return False
|
||||
|
||||
def isalive(self, console=True):
|
||||
def isalive(self, trust_console=True):
|
||||
"""True if the child is still alive, false otherwise"""
|
||||
if trust_console:
|
||||
if self.flag_eof:
|
||||
return False
|
||||
|
||||
if self.child_process is None:
|
||||
# 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,
|
||||
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):
|
||||
pipe_name = 'wexpect_{}'.format(self.console_pid)
|
||||
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,
|
||||
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):
|
||||
"""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
|
||||
|
Loading…
Reference in New Issue
Block a user