- Как запустить скрипт Python с Os.fork на окнах?
- 3 ответа
- Saved searches
- Use saved searches to filter your results more quickly
- Error ‘module’ object has no attribute ‘fork’ under Windows 10 #859
- Error ‘module’ object has no attribute ‘fork’ under Windows 10 #859
- Comments
- Saved searches
- Use saved searches to filter your results more quickly
- AttributeError: module ‘os’ has no attribute ‘fork’ when connecting from Linux machine to Windows machine #706
- AttributeError: module ‘os’ has no attribute ‘fork’ when connecting from Linux machine to Windows machine #706
- Comments
- Saved searches
- Use saved searches to filter your results more quickly
- [Bug] AttributeError: module ‘os’ has no attribute ‘fork’ #7
- [Bug] AttributeError: module ‘os’ has no attribute ‘fork’ #7
- Comments
Как запустить скрипт Python с Os.fork на окнах?
Команда os.fork() не поддерживается в Windows и выдает следующую ошибку:
AttributeError: 'module' object has no attribute 'fork'
Итак, общий вопрос: Как запустить скрипт, который содержит вызов os.fork() в Windows? . Я не против использования чего-то, что только моделирует поведение и работает намного медленнее, это только для тестирования. Я также предпочитаю не менять скрипт, так как это сторонний модуль.
Чтобы дать вам более широкую перспективу, я пытаюсь использовать модуль rq a.k.a redis queue в Windows. В конце концов я буду запускать код на сервере heroku, который является машиной Linux, но во время разработки веб-приложения я использую Windows.
3 ответа
Нет простого способа эмулировать fork() в системах, в которых его нет, например в Windows. Если код использует только fork() для запуска нового процесса с exec , вы можете перенести его на использование subprocess . Но это , похоже, не так в Так что у вас есть несколько вариантов:
- Порт rq в Windows или попросите кого-нибудь сделать это за вас. Самый простой способ перенести часть кода, которая вызывает fork() , может быть с помощью модуля multiprocessing . Однако вам все равно придется заменить другие части кода, которые зависят от Unix, такие как использование signal.alarm() в модуле timeouts .
- Используйте Python под Cygwin, который эмулирует полностью функциональный (хотя и медленный) fork() , поэтому у Cygwin Python есть рабочий os.fork() . Обратите внимание, что для получения os.fork() вам нужно будет использовать Python, построенный на Cygwin, такой как тот, который поставляется Cygwin, а not просто запустить обычный Python для Windows под Cygwin.
- Протестируйте приложение на Linux, работающем на виртуальной машине.
Среди этих несчастных вариантов я бы порекомендовал последний.
На Windows вы можете установить Cygwin с Python. Эта установка на python будет иметь модуль os, который будет поддерживать вызов os.fork ().
Импортируйте оболочку, которая условно оборачивает соответствующий вызов подпроцесса в функцию с именем fork и добавляет ее в пространство имен os.
Возможно, это будет возможность связаться с продавцом и указать, что os.fork не является для вас предпочтительным вариантом.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
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
Error ‘module’ object has no attribute ‘fork’ under Windows 10 #859
Error ‘module’ object has no attribute ‘fork’ under Windows 10 #859
Comments
I am trying to using rq under windows 10, but get an error in worker:
File "c:\dev\src\rq\rq\worker.py", line 474, in work self.execute_job(job, queue) File "c:\dev\src\rq\rq\worker.py", line 592, in execute_job self.fork_work_horse(job, queue) File "c:\dev\src\rq\rq\worker.py", line 534, in fork_work_horse child_pid = os.fork() AttributeError: 'module' object has no attribute 'fork'
The text was updated successfully, but these errors were encountered:
Windows Linux Subsystem supports FORK.
The way to get this working, is:
- You will need the Windows Linux Subsystem. as of not not widely released: https://docs.microsoft.com/en-us/windows/wsl/install-win10
- Then you go to the Microsoft Store and install a linux distro and run it.. (this actually does the install)
- In your command prompt (or vs code terminal) you can then run bash and from there you can pip install rq and then run the worker.
In my case, I am running redis in a container at localhost:32768
So in following the samples they change so that you setup your connection and yoru worker like this:
os.fork() only works with Linux operating systems, and with Win10 you can use the cross-platform multiprocessing module
Hey guys! This Python God I have on vc helped me a little. Try running this
python -m pip install https://github.com/michaelbrooks/rq-win.git@c6e65e38f8a6ca99a0c8e0dd6fe35f9b92837cca
If that doesn’t work, try this:
py -m pip install rq-win @ git+https://github.com/michaelbrooks/rq-win.git@c6e65e38f8a6ca99a0c8e0dd6fe35f9b92837cca
but the thing would fail because both CMD and Powershell don’t like @ at all. So put it in a requirements.txt file and do py -m pip install -r requirements.txt
Is it possible to use https://docs.python.org/3/library/multiprocessing.html instead since it works everywhere?
I’m open to changing the underlying worker to use multi processing. So please open a PR and I’ll review it.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
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
AttributeError: module ‘os’ has no attribute ‘fork’ when connecting from Linux machine to Windows machine #706
AttributeError: module ‘os’ has no attribute ‘fork’ when connecting from Linux machine to Windows machine #706
Comments
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 "", line 1, in module> E File "", 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
The text was updated successfully, but these errors were encountered:
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
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
[Bug] AttributeError: module ‘os’ has no attribute ‘fork’ #7
[Bug] AttributeError: module ‘os’ has no attribute ‘fork’ #7
Comments
Python version: 3.10.8
Hap version: 0.1.6
Traceback (most recent call last): File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\Scripts\hap.exe\__main__.py", line 7, in module> File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1130, in __call__ return self.main(*args, **kwargs) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1055, in main rv = self.invoke(ctx) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1657, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1404, in invoke return ctx.invoke(self.callback, **ctx.params) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 760, in invoke return __callback(*args, **kwargs) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\hapless\cli.py", line 101, in run hapless.run(cmd_escaped, name=name, check=check) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\hapless\main.py", line 253, in run pid = os.fork() AttributeError: module 'os' has no attribute 'fork' PS C:\Users\caeden\Github\hap-test> hap run py .\while_test.py Traceback (most recent call last): File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\Scripts\hap.exe\__main__.py", line 7, in module> File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1130, in __call__ return self.main(*args, **kwargs) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1055, in main rv = self.invoke(ctx) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1657, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1404, in invoke return ctx.invoke(self.callback, **ctx.params) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 760, in invoke return __callback(*args, **kwargs) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\hapless\cli.py", line 101, in run hapless.run(cmd_escaped, name=name, check=check) File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\hapless\main.py", line 253, in run pid = os.fork() AttributeError: module 'os' has no attribute 'fork'
Seems like an issue because I’m using it on windows
The text was updated successfully, but these errors were encountered: