Fabric: python3μ—μ„œ 병렬 μ‹€ν–‰

에 λ§Œλ“  2018λ…„ 12μ›” 02일  Β·  14μ½”λ©˜νŠΈ  Β·  좜처: fabric/fabric

μ΅œμ‹  패브릭 버전에 λŒ€ν•œ 병렬 싀행에 λŒ€ν•œ λ¬Έμ„œλ₯Ό 찾을 수 μ—†μ—ˆμŠ΅λ‹ˆλ‹€. python 2 버전과 λ™μΌν•©λ‹ˆκΉŒ, μ•„λ‹ˆλ©΄ μž‘μ—… μ€‘μž…λ‹ˆκΉŒ?

감사 ν•΄μš”!

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

@akiuni 이에 λŒ€ν•œ 홍보가 μžˆμŠ΅λ‹ˆκΉŒ? #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 이에 λŒ€ν•œ 홍보가 μžˆμŠ΅λ‹ˆκΉŒ? https://github.com/fabric/fabric/issues/1912#issuecomment -464652728

@akiuni 이에 λŒ€ν•œ 홍보가 μžˆμŠ΅λ‹ˆκΉŒ? #1912(λŒ“κΈ€)

μ•ˆλ…•ν•˜μ„Έμš”..κ·Έλ ‡κ²Œ 생각이 μ•ˆλ‚˜μš”.. μ†”μ§νžˆ 확인 방법은 μ•Œκ² λŠ”λ° μ–΄λ–»κ²Œ μ €λŸ° μˆ˜μ • μ œμΆœμ„ 해야할지 λͺ¨λ₯΄κ² λ„€μš”...

이것을 Fabric에 μ΅œλŒ€ν•œ 빨리 병합해야 ν•©λ‹ˆλ‹€.

mm v 2.5.0의 ν˜„μž¬ μ½”λ“œλ₯Ό 보고 μžˆμŠ΅λ‹ˆλ‹€.
https://github.com/fabric/fabric/blob/2.5.0/fabric/group.py#L127 이 μ½”λ“œλŠ” 더 이상 μ΅œμ‹  μ½”λ“œκ°€ μ•„λ‹ˆλ©° μž‘μ„±μžκ°€ 이λ₯Ό κ΅¬ν˜„ν•˜λŠ” κ°€μž₯ 쒋은 방법에 λŒ€ν•΄ μƒκ°ν•˜κ³  μžˆμŒμ„ μ•Œ 수 μžˆμŠ΅λ‹ˆλ‹€. λ˜ν•œ PR이 μ—†μœΌλ©΄ μ½”λ“œκ°€ λ„μž…ν•˜λŠ” λ³€κ²½ 사항을 λ…Όμ˜ν•  ν”Œλž«νΌμ΄ μ—†μŠ΅λ‹ˆλ‹€. 이거 보고 μžˆλŠ”λ° 파이썬 μ „λ¬Έ μ½”λ”λŠ” μ•„λ‹ˆμ§€λ§Œ ν™λ³΄μš©μœΌλ‘œ ν•œλ²ˆ ν•΄λ³Όκ»˜μš”

μ—¬κΈ°μ—μ„œ 홍보: https://github.com/fabric/fabric/pull/2052

μ•ˆλ…•ν•˜μ„Έμš”, μ €λŠ” git developmentpemen에 μ΅μˆ™ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€(PR은 μ €μ—κ²Œ μ΄μƒν•œ λ‹¨μ–΄μž…λ‹ˆλ‹€). μ œκ°€ λ„μšΈ 수 있으면 μ–Έμ œλ“ μ§€ 말씀해 μ£Όμ‹­μ‹œμ˜€.

μ•ˆλ…•ν•˜μ„Έμš” @akiuni
PR은 λŒμ–΄μ˜€κΈ° μš”μ²­(Pull Request)의 μ•½μžμ΄λ©°, λ³€κ²½ν•˜λ €λŠ” 경우 λŒμ–΄μ˜€κΈ° μš”μ²­μ„ 톡해 ν•΄λ‹Ή λ³€κ²½ 사항을 μ†ŒμŠ€ μ½”λ“œλ‘œ κ°€μ Έμ˜¨ λ‹€μŒ 승인될 λ•ŒκΉŒμ§€ λŒ€ν™”λ‘œ 처리되고 검토될 수 μžˆμŒμ„ μ˜λ―Έν•©λ‹ˆλ‹€. 승인되면 μ—¬κΈ°μ—μ„œ μˆ˜ν–‰ν•œ κ²ƒμ²˜λŸΌ PR이 λ„μž…ν•œ λ³€κ²½ 사항을 μ»€λ°‹μœΌλ‘œ λ‹€μ‹œ 좔적할 수 μžˆμŠ΅λ‹ˆλ‹€. #2052
μ˜λ¦¬ν•œ νŠΈλ¦­μ€ https://patch-diff.githubusercontent.com/raw/fabric/fabric/pull/2052.patch 와 같이 pull μš”μ²­(PR)에 ".patch"λ₯Ό μΆ”κ°€ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€. 그러면 diffκ°€ μ œκ³΅λ©λ‹ˆλ‹€. λ³€κ²½ 사항(이전 μ˜κ²¬μ—μ„œ μ œκ³΅ν•œ λŒ€λ‘œ)μ΄μ§€λ§Œ 이제 이점은 μœ„μ—μ„œ μ–ΈκΈ‰ν•œ λŒ€λ‘œ λŒ€ν™”/κ²€ν† /λ³€κ²½ μ‚¬ν•­μ˜ 단일 μ§€μ μž…λ‹ˆλ‹€. ν•˜μ§€λ§Œ 이에 λŒ€ν•œ 패치λ₯Ό 처음으둜 μ μš©ν•΄ μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€. λ‚΄κ°€ PR을 λ§Œλ“œλŠ” λ™μ•ˆ

SudoλŠ” μ§€κΈˆ 그룹에 μΆ”κ°€λ˜κ³  μžˆμŠ΅λ‹ˆλ‹€! #1999 μ°Έμ‘°

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰