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

Reasoning why subprocess is not available over pexpect #1399

Open
evanraalte opened this issue Oct 10, 2024 · 0 comments
Open

Reasoning why subprocess is not available over pexpect #1399

evanraalte opened this issue Oct 10, 2024 · 0 comments
Labels
needs_triage New item that needs to be triaged

Comments

@evanraalte
Copy link

Hi!

First of all thank you for providing this library!

.venv/lib/python3.12/site-packages/ansible_runner/config/runner.py line 74 sets self.runner_mode = "pexpect", without an apparent option to override it. What is the reason for doing it like this? In some of the other interface calls I do see the option to set subprocess instead.

The reason that I am asking this, is that in Python 3.12, I am getting Deprecation warnings on unit tests that use the ansible-runner:
DeprecationWarning: This process (pid=xxxx) is multi-threaded, use of forkpty() may lead to deadlocks in the child.

I isolated this to this minimal example, that shows that this is due to pexpect calls:

def test_pexpect_spawn_process():
    child = pexpect.spawn("python3")

I was able to "overwrite" the running_mode to use subprocess with this ugly hack:

        from ansible_runner import Runner
        from ansible_runner.utils import dump_artifacts

        def run_wrapper(**kwargs) -> Runner:  # type: ignore[no-untyped-def]  # noqa: ANN003
            dump_artifacts(kwargs)
            runner_config = ansible_runner.RunnerConfig(**kwargs)
            runner_config.prepare()
            runner_config.runner_mode = "subprocess"
            runner = Runner(runner_config)
            runner.run()
            return runner

And now my unit tests work as expected without the warning. However, I am not going to use this, as it seems like I am misusing the lib :). Can you perhaps clarify why it is that way? I searched through the latest docs, as well as for 2.4.0 (the version I am using), but could not find anything. Thank you in advance!

@github-actions github-actions bot added the needs_triage New item that needs to be triaged label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs_triage New item that needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant