0

When run in cmd window, the spawn command works fine, but if in a virtual environment, it hangs forever.

This works

C:\Users\csullivan\Documents\Projects\netlog>python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from wexpect import spawn
>>> spawn("cmd.exe")
<wexpect.host.SpawnPipe object at 0x0000019F7040DBB0>
>>>

but this does not return from spawn.

(env) C:\Users\csullivan\Documents\Projects\netlog>python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from wexpect import spawn
>>> spawn("cmd.exe")

I expected or at least hoped for identical behaviour in a Python Virtual Environment if software versions are the same, which they are.

Environment

  • Microsoft Windows 10 Pro 10.0.19043 Build 19043
  • Dell Latitude 7490
  • Python 3.9.5
  • wexpect 4.0.0

Is there anything special about running from a virtualenv that could be relevant? I started this exercise for testing an interactive C program with unittest using subprocess, and it worked until I needed to actually interact with it. Then I tried pexpect. That at least did not hang on Popen_spawn but did later despite using timeout=1 on reads.

If this isn't going to work, is there perhaps a C API that has similar functionality or enough to provide read/write functions to a command window or directly with the application?

Deepstop
  • 3,627
  • 2
  • 8
  • 21
  • Do you have the same versions of `wexpect` in global python and in your `env` python? – Yevhen Kuzmovych Jul 08 '21 at 13:18
  • Yes 4.0.0 in both, and the dependencies (`psutil` and `filelock`) are the same as well. – Deepstop Jul 08 '21 at 13:38
  • I submitted a bug report to `wexpect` and received a reply that included a Stack Overflow post (https://stackoverflow.com/questions/61290972/popen-creates-one-additional-process-in-venv) on using it with `venv`. I'm using `virtualenv` and the same considerations don't seem to apply. I ended up going back to using `subprocess.Popen` with threads which seems to only return anything once the program in the child subprocess exits but it at least allows me to achieve my goal of running functional tests. – Deepstop Jul 12 '21 at 13:32

1 Answers1

0

This is a known issue with wexpect. Initially reported only with venv, some changes to virtualenv to align it with venv have triggered the problem, although the behaviour is not identical. Although there is a suggest patch, I've been able to achieve my objective by using subprocess directly and combining it with threading, despite some annoying quirks.

Deepstop
  • 3,627
  • 2
  • 8
  • 21