Fabric: python3での並列実行

作成日 2018年12月02日  ·  14コメント  ·  ソース: fabric/fabric

新しいファブリックバージョンの並列実行に関するドキュメントが見つかりませんでした。 Python 2バージョンと同じですか、それとも進行中ですか?

ありがとう!

最も参考になるコメント

@akiuniこれのPRはありますか? #1912(コメント)

こんにちは、私はそうは思いません..正直なところ、私はそれを確認する方法を知っています、そして私はそのような変更を提出する方法を知りません...

全てのコメント14件

はい。ただし、スレッドグループは構成をサポートしていません。特に次の点に注意してください。

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

コマンドサポートを書き直して追加できます。

SerialGroupとThreadingGroupでsudoを有効にする次のパッチについてどう思いますか?
(ファブリック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()機能をFabric2のThreadingGroupに戻すとよいでしょう。

@akiuniこれのPRはありますか? https://github.com/fabric/fabric/issues/1912#issuecomment -464652728

@akiuniこれのPRはありますか? #1912(コメント)

こんにちは、私はそうは思いません..正直なところ、私はそれを確認する方法を知っています、そして私はそのような変更を提出する方法を知りません...

これをできるだけ早くFabricにマージする必要があります。

mm v2.5.0の現在のコードを見る
https://github.com/fabric/fabric/blob/2.5.0/fabric/group.py#L127このコードは最新ではなく、作成者はこれを実装するための最良の方法を考えていることがわかり

ここでのPR: https ://github.com/fabric/fabric/pull/2052

こんにちは、私は開発者をgitすることに慣れていません(PRは私にとって奇妙な言葉です)、私が助けることができるかどうか私に教えてください

ねえ@akiuni
PRはプルリクエストの略で、変更を加える場合は、プルリクエストを介してその変更をソースコードに取り込み、承認されるまで会話として扱い、確認することができます。 承認されると、PRが導入する変更は、私がここで行ったようにコミットにまでさかのぼることができます:#2052
巧妙なトリックは、次のようにプルリクエスト(PR)に「.patch」を追加することです: https ://patch-diff.githubusercontent.com/raw/fabric/fabric/pull/2052.patchこれにより、差分が得られます変更の(以前のコメントで提供したように)しかし今、利点は、私が上で述べたように会話/レビュー/単一の変更点です-しかし、これのパッチを最初に持ってくれてありがとう、私は探していましたPRを作成している間

現在、Sudoがグループに追加されています! #1999を参照

このページは役に立ちましたか?
0 / 5 - 0 評価