2015-01-23 1 views
0

많은 양의 git 저장소에서 동시에 작업을 수행 할 파이썬 코드를 작성하고 있습니다. 이렇게하려면 concurrent.futuresGitPython을 결합하여 각 저장소를 별도의 향후 작업으로 복제하려고합니다. 이것은 내장 된 Python 2.7.6을 OS X 10.10 및 GitPython 0.3.5 및 future 2.2.0 (버전 2.7로 다시 포팅 됨)을 사용하여 pip를 통해 설치합니다.GitPython은 concurrent.futures.ThreadPoolExecutor가 max_workers를 무시하도록합니다.

import time 
from concurrent import futures 
import shutil 
import os 
from git import Repo 


def wait_then_return(i): 
    print('called: %s', i) 
    time.sleep(2) 
    return i 


def clone_then_return(i): 
    print('called: %s', i) 
    path = os.path.join('/tmp', str(i)) 
    os.mkdir(path) 
    # clone some arbitrary repo 
    Repo.clone_from('https://github.com/ros/rosdistro', path) 
    shutil.rmtree(path) 
    return i 



if __name__ == "__main__": 

    tasks = 20 
    workers = 4 

    with futures.ThreadPoolExecutor(max_workers=workers) as executor: 

     # this works as expected... delaying work until a thread is available 
     # fs = [executor.submit(wait_then_return, i) for i in range(0, tasks)] 
     # this doesn't... all 20 come in quick succession 
     fs = [executor.submit(clone_then_return, i) for i in range(0, tasks)] 

     for future in futures.as_completed(fs): 
      print('result: %s', future.result()) 

내가 집행에 wait_then_return 기능을 제출하면, 나는 예상되는 동작을 얻을 : 인쇄가 4의 그룹에서 수행되어 다음과 같이

내가 사용하고 코드의 간단한 예입니다 먼저 모든 선물이 완성 될 때까지 그 라인을 따라 대략적으로. 만약 내가 clone_then_return로 바꾸면 실행자가 max_workers 인수를 무시하고 동시에 20 개의 미래를 모두 실행하는 것처럼 보입니다.

그 원인은 무엇일까요?

답변

0

사실 내가 사용하고 있던 자식 호출에는 미래가 빨리 완료 될 수있는 인증 문제가있었습니다. 동시성의 세계에서는 모두 여전히 제정신이 아닙니다.

+0

gitpython 관련 문제가 아닐 경우이 질문에 답변 할 수 있습니까? – Byron

+0

죄송합니다. 지금 해. –

관련 문제