COM64 : |
אני כותב קוד שבצע מספר רב של פעולות שמבחינת משאבי מיחשוב דורשות מעט מאד אך זמן הביצוע של כל אחת מגיע לעשרות שניות. אין קשר או תלות בין הפעולות.
אני רוצה להריץ את כולן במקביל, מה ההבדלים בין threading ל-multiprocessing? האם יש עדיפות לאחת מהן כשמה שנדרש לביצוע הוא חיבור לציוד רשת מרוחק, הרצת מספר פקודות על הציוד ואיסוף של המידע שהתקבל לתוך רשימה או קובץ json? תודה ! |
קוד: |
import asyncio async def myfunc(): return 42 |
Anonymous : |
python פשוט לא תומכת ב multi-threadings שמשתמש ב multi-core. כשאתה יוצר thread בפייתון, הוא תמיד רץ על אותו מעבד כמו האבא. זה מה יש.
מזכיר לי שורת הערה שראיתי בקוד רלוונטי, שבו כתוב (תרגום עקום): "אני מפחד לחפש בגוגל איך לפתור את הבעיה - כיצד הורה יכול להרוג את הילד..." חוש הומור של מפתחים |
queency : |
אם תהיה יותר פרטני יביאו לך רעיונות לפתרון שאולי בכלל לא חשבת
עליהם ומפשטים את הקוד. |
Anonymous : |
מה לגבי שימוש במשהו קיים במקום להמציא את הגלגל
https://parallel-ssh.readthedocs.io |
Anonymous : |
אם יש צורך בניהול מקביל של פעולות שונות ולא רק ssh אז - שרת ג׳ובים
https://edgeguides.rubyonrails.org/active_job_basics.html או משהוא דומה שיש ב python כי אחרת יש עוד דברים שלא חשבתה עליהם (מה אם הפרוסס מת באופן לא צפוי ועוד...) |
ציטוט: |
נראה שזה לא עובד עם פייתון 3.7 כשיש צורך לבצע לוגין ב-SSH עם שם משתמש וסיסמה. יש באג על זה מ-2018 והגירסה העדכנית ביותר גם מ-2018. במקרה שלי לא קיימת אפשרות להשתמש במפתחות |
Anonymous : | ||
אפשר לשאול איפה אתה רואה את זה? אני רואה גרסאות מ-2021 והקוד ב-github מתוחזק עם תיקונים ושינויים שוטפים. |
קוד: |
from pssh.clients import ParallelSSHClient
hosts = [‘10.0.0.204’, ‘10.0.0.205’] client = ParallelSSHClient(hosts, user = ‘admin’, password = ‘123456’) client.run_command(‘show run’) |
קוד: |
Traceback (most recent call last):
File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/single.py”, line 208, in _auth_retry self.auth() File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/single.py”, line 355, in auth self._password_auth() File “/usr/local/lib/python3.7/dist-packages/pssh/clients/native/single.py”, line 229, in _password_auth self.session.userauth_password(self.user, self.password) File “ssh2/session.pyx”, line 321, in ssh2.session.Session.userauth_password File “ssh2/utils.pyx”, line 166, in ssh2.utils.handle_error_codes ssh2.exceptions.AuthenticationError During handling of the above exception, another exception occurred: Traceback (most recent call last): File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/single.py”, line 208, in _auth_retry self.auth() File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/single.py”, line 355, in auth self._password_auth() File “/usr/local/lib/python3.7/dist-packages/pssh/clients/native/single.py”, line 229, in _password_auth self.session.userauth_password(self.user, self.password) File “ssh2/session.pyx”, line 321, in ssh2.session.Session.userauth_password File “ssh2/utils.pyx”, line 166, in ssh2.utils.handle_error_codes ssh2.exceptions.AuthenticationError During handling of the above exception, another exception occurred: Traceback (most recent call last): File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/single.py”, line 208, in _auth_retry self.auth() File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/single.py”, line 355, in auth self._password_auth() File “/usr/local/lib/python3.7/dist-packages/pssh/clients/native/single.py”, line 229, in _password_auth self.session.userauth_password(self.user, self.password) File “ssh2/session.pyx”, line 321, in ssh2.session.Session.userauth_password File “ssh2/utils.pyx”, line 166, in ssh2.utils.handle_error_codes ssh2.exceptions.AuthenticationError During handling of the above exception, another exception occurred: Traceback (most recent call last): File “”, line 1, in File “/usr/local/lib/python3.7/dist-packages/pssh/clients/native/parallel.py”, line 217, in run_command return_list=return_list, read_timeout=read_timeout if read_timeout else timeout, File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/parallel.py”, line 198, in run_command return_list=return_list) File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/parallel.py”, line 204, in _get_output_from_cmds finished = joinall(_cmds, raise_error=True) File “src/gevent/greenlet.py”, line 849, in gevent._greenlet.joinall File “src/gevent/greenlet.py”, line 865, in gevent._greenlet.joinall File “src/gevent/greenlet.py”, line 312, in gevent._greenlet.Greenlet._raise_exception File “/usr/lib/python3/dist-packages/gevent/_compat.py”, line 47, in reraise raise value.with_traceback(tb) File “src/gevent/greenlet.py”, line 716, in gevent._greenlet.Greenlet.run File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/parallel.py”, line 216, in _get_output_from_greenlet raise ex File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/parallel.py”, line 209, in _get_output_from_greenlet host_out = cmd.get() File “src/gevent/greenlet.py”, line 633, in gevent._greenlet.Greenlet.get File “src/gevent/greenlet.py”, line 312, in gevent._greenlet.Greenlet._raise_exception File “/usr/lib/python3/dist-packages/gevent/_compat.py”, line 47, in reraise raise value.with_traceback(tb) File “src/gevent/greenlet.py”, line 716, in gevent._greenlet.Greenlet.run File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/parallel.py”, line 285, in _run_command raise ex File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/parallel.py”, line 277, in _run_command _client = self._make_ssh_client(host_i, host) File “/usr/local/lib/python3.7/dist-packages/pssh/clients/native/parallel.py”, line 252, in _make_ssh_client identity_auth=self.identity_auth, File “/usr/local/lib/python3.7/dist-packages/pssh/clients/native/single.py”, line 129, in init identity_auth=identity_auth) File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/single.py”, line 195, in init self._init() File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/single.py”, line 200, in _init self._auth_retry() File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/single.py”, line 212, in _auth_retry return self._auth_retry(retries=retries+1) File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/single.py”, line 212, in _auth_retry return self._auth_retry(retries=retries+1) File “/usr/local/lib/python3.7/dist-packages/pssh/clients/base/single.py”, line 214, in _auth_retry raise AuthenticationError(msg, self.host, self.port, ex) pssh.exceptions.AuthenticationError: (‘Authentication error while connecting to %s:%s - %s’, ‘10.0.0.204’, 22, AuthenticationError()) |