Fabric: التنفيذ الموازي تحت بيثون 3

تم إنشاؤها على ٢ ديسمبر ٢٠١٨  ·  14تعليقات  ·  مصدر: fabric/fabric

لم أتمكن من العثور على أي مستندات بشأن التنفيذ المتوازي لإصدار قماش أحدث. هل هو نفس إصدار Python 2 ، أم أنه يعمل؟

شكرا!

التعليق الأكثر فائدة

akiuni هل هناك علاقات عامة لهذا؟ # 1912 (تعليق)

مرحبًا ، لا أعتقد ذلك .. لأكون صادقًا ، أعرف كيفية التحقق من ذلك ولا أعرف كيفية المتابعة لتقديم مثل هذا التعديل ...

ال 14 كومينتر

نعم ، ومع ذلك ، لا تدعم مجموعة Threading التكوينات ، على وجه الخصوص:

config = Config(overrides={'sudo':{'password': 'changeme'}})

c = ThreadingGroup("[email protected]", "[email protected]", connect_kwargs={"password": "changeme"}, config=config)

c.run("whoami")

c.sudo("whoami") #Throws AttributeError: 'ThreadingGroup' object has no attribute 'sudo'

يسمح ThreadingGroup فقط بتشغيل الأمر.
https://github.com/fabric/fabric/issues/1899#issue -377714688

يمكنك إعادة كتابة وإضافة دعم الأوامر.

ما رأيك في التصحيح التالي لتمكين sudo في SerialGroup و ThreadingGroup؟
(مطبق ومختبر على القماش 2.4)

--- fabric-orig/group.py    2018-10-30 14:35:22.000000000 +0100
+++ fabric-patched/group.py 2019-02-18 10:16:29.186000000 +0100
@@ -183,12 +183,28 @@
             raise GroupException(results)
         return results

+    def sudo(self, *args, **kwargs):
+        results = GroupResult()
+        excepted = False
+        for cxn in self:
+            try:
+                results[cxn] = cxn.sudo(*args, **kwargs)
+            except Exception as e:
+                results[cxn] = e
+                excepted = True
+        if excepted:
+            raise GroupException(results)
+        return results

 def thread_worker(cxn, queue, args, kwargs):
     result = cxn.run(*args, **kwargs)
     # TODO: namedtuple or attrs object?
     queue.put((cxn, result))

+def thread_worker_sudo(cxn, queue, args, kwargs):
+    result = cxn.sudo(*args, **kwargs)
+    # TODO: namedtuple or attrs object?
+    queue.put((cxn, result))

 class ThreadingGroup(Group):
     """
@@ -208,6 +224,49 @@
             )
             threads.append(thread)
         for thread in threads:
+            thread.start()
+        for thread in threads:
+            # TODO: configurable join timeout
+            # TODO: (in sudo's version) configurability around interactive
+            # prompting resulting in an exception instead, as in v1
+            thread.join()
+        # Get non-exception results from queue
+        while not queue.empty():
+            # TODO: io-sleep? shouldn't matter if all threads are now joined
+            cxn, result = queue.get(block=False)
+            # TODO: outstanding musings about how exactly aggregate results
+            # ought to ideally operate...heterogenous obj like this, multiple
+            # objs, ??
+            results[cxn] = result
+        # Get exceptions from the threads themselves.
+        # TODO: in a non-thread setup, this would differ, e.g.:
+        # - a queue if using multiprocessing
+        # - some other state-passing mechanism if using e.g. coroutines
+        # - ???
+        excepted = False
+        for thread in threads:
+            wrapper = thread.exception()
+            if wrapper is not None:
+                # Outer kwargs is Thread instantiation kwargs, inner is kwargs
+                # passed to thread target/body.
+                cxn = wrapper.kwargs["kwargs"]["cxn"]
+                results[cxn] = wrapper.value
+                excepted = True
+        if excepted:
+            raise GroupException(results)
+        return results
+
+    def sudo(self, *args, **kwargs):
+        results = GroupResult()
+        queue = Queue()
+        threads = []
+        for cxn in self:
+            my_kwargs = dict(cxn=cxn, queue=queue, args=args, kwargs=kwargs)
+            thread = ExceptionHandlingThread(
+                target=thread_worker_sudo, kwargs=my_kwargs
+            )
+            threads.append(thread)
+        for thread in threads:
             thread.start()
         for thread in threads:
             # TODO: configurable join timeout

سيكون هذا بصراحة رائع akiuni

سيكون من الجيد إعادة ميزة execute () إلى ThreadingGroup لـ Fabric2.

akiuni هل هناك علاقات عامة لهذا؟ https://github.com/fabric/fabric/issues/1912#issuecomment -464652728

akiuni هل هناك علاقات عامة لهذا؟ # 1912 (تعليق)

مرحبًا ، لا أعتقد ذلك .. لأكون صادقًا ، أعرف كيفية التحقق من ذلك ولا أعرف كيفية المتابعة لتقديم مثل هذا التعديل ...

نحتاج إلى دمج هذا في Fabric في أسرع وقت ممكن.

مم بالنظر إلى الكود الحالي في الإصدار 2.5.0
https://github.com/fabric/fabric/blob/2.5.0/fabric/group.py#L127 أستطيع أن أرى أن هذا الكود لم يعد محدثًا ، وأن المؤلفين يفكرون في أفضل طريقة لتنفيذ ذلك. أيضًا مع عدم وجود علاقات عامة ، ليس لديهم منصة لمناقشة التغييرات التي أدخلتها الكود. أنا أنظر إلى هذا ، لكنني لست خبيرًا في ترميز لغة الثعبان ، لكنني سأحاول أن أجربها كمسؤول علاقات عامة

العلاقات العامة هنا: https://github.com/fabric/fabric/pull/2052

مرحبًا ، لست معتادًا على git developmentpemen (العلاقات العامة كلمة غريبة بالنسبة لي) ، لا تتردد في إخباري إذا كان بإمكاني المساعدة

ياakiuni
يرمز PR إلى Pull Request ، وهذا يعني ، إذا كنت ترغب في إجراء تغيير ، فأنت تقوم بإدخال هذا التغيير في التعليمات البرمجية المصدر عبر طلب سحب ، والذي يمكن بعد ذلك التعامل معه كمحادثة ، ومراجعته ، حتى تتم الموافقة عليه. عندما تتم الموافقة عليه ، يمكن إرجاع التغييرات التي يقدمها PR إلى التزام كما فعلت هنا: # 2052
الحيلة الذكية هي إضافة ".patch" إلى طلب السحب (PR) مثل هنا: https://patch-diff.githubusercontent.com/raw/fabric/fabric/pull/2052.patch والتي ستمنحك بعد ذلك فرقًا من التغييرات (كما ذكرت في تعليقك السابق) ولكن الآن ، الفائدة هي المحادثة / المراجعة / نقطة التغيير الفردية كما ذكرت أعلاه - شكرًا لك على كونك أول شخص لديه تصحيح لهذا على الرغم من ذلك ، كنت أبحث في حين أنشأت العلاقات العامة

تتم إضافة Sudo إلى Group الآن! انظر # 1999

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات

القضايا ذات الصلة

Grazfather picture Grazfather  ·  4تعليقات

supriyopaul picture supriyopaul  ·  4تعليقات

neemxyang picture neemxyang  ·  6تعليقات

acdha picture acdha  ·  4تعليقات

omzev picture omzev  ·  6تعليقات