Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Critical Performance Issue #53

Open
corradods opened this issue Dec 13, 2021 · 2 comments
Open

Critical Performance Issue #53

corradods opened this issue Dec 13, 2021 · 2 comments

Comments

@corradods
Copy link

corradods commented Dec 13, 2021

Describe the bug
if I don't interact with the process, expect() takes increasing time to return.
what is most strange is that elapsed time will slowly approach the time between two sendline (inactivity time).
More time passes between two sendline, more times it takes for returning after I execute a new sendline().

To Reproduce

import wexpect
import time

child = wexpect.spawn('cmd.exe')
child.expect('>')
for _ in range(10):
    child.sendline('echo "hello"')
    starting_time = time.time()
    child.expect('>')
    print("Expect Elapsed time:",time.time() -starting_time)
    time.sleep(5) #if you execute sleep(10) expect will soon take 10 seconds instead of 5
child.sendline('exit')
child.wait()

Expected behavior
"Expect elapsed time" shouldn't depend on how much time I didn't iteracted with the process.

Output
Expect Elapsed time: 0.07507729530334473
Expect Elapsed time: 2.6089940071105957
Expect Elapsed time: 3.860004425048828
Expect Elapsed time: 4.498199224472046
Expect Elapsed time: 4.816983938217163
Expect Elapsed time: 4.947844982147217
Expect Elapsed time: 5.021565198898315
Expect Elapsed time: 5.082917213439941
Expect Elapsed time: 5.092726707458496
Expect Elapsed time: 5.106329441070557

Environment:

  • [windows version] 21H1 - Build 19043.1348
  • [Python version] 3.85
  • [wexpect version] 4.0.0
@raczben
Copy link
Owner

raczben commented Dec 15, 2021

I (the author) finished my profession as an engineer, now I'm in novitiate of Jesuits.
I'm sorry. I cant help now.

@corradods
Copy link
Author

corradods commented Apr 29, 2022

I don't know why time.sleep(0.01) statement is needed, but it is the source of the bad behaviour. If the sleep statement is removed, the behaviour fades away.

#file: /master/wexpect/host.py    
#line: 828
   # Still have time left, so read more data
                self.isalive()
                c = self.read_nonblocking(self.maxread)
                freshlen = len(c)
                time.sleep(0.01) #<-- 
                incoming += c

Output:
Expect Elapsed time: 0.04537820816040039
Expect Elapsed time: 0.031409502029418945
Expect Elapsed time: 0.030704021453857422
Expect Elapsed time: 0.030231475830078125
Expect Elapsed time: 0.04694247245788574
Expect Elapsed time: 0.03125119209289551
Expect Elapsed time: 0.031536102294921875
Expect Elapsed time: 0.046549081802368164
Expect Elapsed time: 0.04633355140686035
Expect Elapsed time: 0.046590328216552734

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants