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

Closed
evanraalte opened this issue Oct 10, 2024 · 1 comment
Closed

Reasoning why subprocess is not available over pexpect #1399

evanraalte opened this issue Oct 10, 2024 · 1 comment

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
@Shrews
Copy link
Contributor

Shrews commented Dec 5, 2024

None of the original developers for runner are currently working on the project, so I can only speculate, but I would speculate that subprocess is not available as it doesn't provide a way to handle sending passwords when prompted from Ansible. Of course, if you aren't using Ansible in a way that it would prompt for passwords, subprocess would be usable, but it appears that option was not considered in the design.

@Shrews Shrews removed the needs_triage New item that needs to be triaged label Dec 5, 2024
@Shrews Shrews closed this as completed Dec 5, 2024
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