mitogen-hq / mitogen

Distributed self-replicating programs in Python
https://mitogen.networkgenomics.com/
BSD 3-Clause "New" or "Revised" License
2.34k stars 199 forks source link

AttributeError: module 'os' has no attribute 'fork' when connecting from Linux machine to Windows machine #706

Open jiridanek opened 4 years ago

jiridanek commented 4 years ago

Host: Python 3.8, Mitogen 0.2.9 Target: Windows Server 2016, Python 3.8 Stacktrace attached

performance_tests.py:256 (SshCmdTest.test_mitogen)
self = <dtestlib.executor.unittests.performance_tests.SshCmdTest testMethod=test_mitogen>

    def test_mitogen(self):
        # @mitogen.main()
        def main(router: mitogen.master.Router):
            bastion = router.ssh(
                hostname='xxx', password='xxx', username="Administrator",
                                 check_host_keys='ignore',
                                 python_path=["C:/Tools/miniconda3/envs/tn/python.exe"]
                )

            whence = time.time()
            for _ in range(100):
                result = bastion.call(run, 'echo baf')
                print(result)
            print(time.time() - whence)

        broker = mitogen.master.Broker()
        router = mitogen.master.Router(broker)

        # router.responder.blacklist.append("typing")

        try:
>           return main(router)

performance_tests.py:290: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
performance_tests.py:265: in main
    python_path=["C:/Tools/miniconda3/envs/tn/python.exe"]
/home/jdanek/.local/share/virtualenvs/dtests-tWfbuz1n/lib/python3.7/site-packages/mitogen/parent.py:2502: in ssh
    return self.connect(u'ssh', **kwargs)
/home/jdanek/.local/share/virtualenvs/dtests-tWfbuz1n/lib/python3.7/site-packages/mitogen/parent.py:2444: in connect
    return self._connect(klass, **mitogen.core.Kwargs(kwargs))
/home/jdanek/.local/share/virtualenvs/dtests-tWfbuz1n/lib/python3.7/site-packages/mitogen/parent.py:2424: in _connect
    conn.connect(context=context)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = Connection(<Stream ssh.10.0.yyy.xxx #5ad0>)
context = Context(1, 'ssh.10.0.yyy.xxx')

    def connect(self, context):
        self.context = context
        self.latch = mitogen.core.Latch()
        self._router.broker.defer(self._async_connect)
        self.latch.get()
        if self.exception:
>           raise self.exception
E           mitogen.parent.EofError: EOF on stream; last 100 lines received:
E           Traceback (most recent call last):
E             File "<string>", line 1, in <module>
E             File "<string>", line 3, in <module>
E           AttributeError: module 'os' has no attribute 'fork'

/home/jdanek/.local/share/virtualenvs/dtests-tWfbuz1n/lib/python3.7/site-packages/mitogen/parent.py:1706: EofError
jiridanek commented 4 years ago

So far, I found no evidence that mitogen actually aims to support Windows.

eltrevii commented 3 years ago

I have the same error with os.fork() and i'm searching for a solution

zxd147 commented 1 year ago

我在os.fork()上遇到了同样的错误,我正在寻找解决方案

你好,请问有找到解决方案吗

eltrevii commented 1 year ago

我在os.fork()上遇到了同样的错误,我正在寻找解决方案

你好,请问有找到解决方案吗

@suonianjiexinghe520 no

jiridanek commented 1 year ago

I have three ideas

  1. implement Windows support for mitogen
  2. use Cygwin's version of CPython, which should support os.fork (https://stackoverflow.com/questions/17300551/how-to-run-python-script-with-os-fork-on-windows)
  3. use Python in Windows Subsystem for Linux, which should also support os.fork

for suggestions 2. and 3., you'd have to (I assume) run either the cygwin's or wsl2's version of sshd, so that afterwards the connection operates inside the respective environment and uses the linux-like version of Python.

I did not try these myself so I am unsure if it will work, but I have high hopes.