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

Port overload when running multiple instances leads to timeout #56

Open
mk-french opened this issue Nov 6, 2022 · 0 comments
Open

Port overload when running multiple instances leads to timeout #56

mk-french opened this issue Nov 6, 2022 · 0 comments

Comments

@mk-french
Copy link

Describe the bug
When executing multiple instances of a script, wexpect overloads on the same port and will typically timeout on the first use of expect(). In some cases, I've observed a race condition where the ConsoleReader of the second process connects to the port of the first and things get a little mixed up...

To Reproduce
Call this script from two seperate terminals without specifying a port. The second instance will time-out on expect('>').
Then call them again but specify unique ports. All is well.

import wexpect
import os
import sys

pid = os.getpid()
if len(sys.argv) > 1:
    port = sys.argv[1]
else:
    port = None

print(f'Started process {pid}, using port {port}')

if not port:
    child = wexpect.host.SpawnSocket(f'cmd.exe', interact=True)
else:
    child = wexpect.host.SpawnSocket(f'cmd.exe', interact=True, port=int(port))

child.expect('>')
print("Prompt detected...")

string = f'echo Hello From {pid}'

child.sendline(string)
child.expect(string)

print(child.match)

wait = input("Press Enter to close.")

An obvious workaround is to specify a unique port to the constructor but it took me a while to work out what was going on...

Expected behavior
If a port is not specified, I would expect the default port to be a random free port.
Or at a minimum, maybe this behaviour could be documented?

Screenshots
N/A

Environment:

  • Windows 10.0.19044.2132
  • Python 3.7.0
  • wexpect 4.0.0

Additional context
N/A

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

1 participant