Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

konlpy와 multiprocessing을 함께 사용할때 에러 메세지 없이 진행이 되지 않는 경우 #411

Open
cxhuy opened this issue Jul 24, 2022 · 0 comments

Comments

@cxhuy
Copy link

cxhuy commented Jul 24, 2022

#298 과 관련이 있을것 같고, 비슷한 문제를 겪는 다른 분들에게 도움이 될까 생각이 들어 남겨둡니다.

konlpy version: 0.6.0

multiprocessing을 사용하여 konlpy 모듈을 여러 process에서 동시에 사용할 경우, 에러 메세지 없이 진행이 막히는 현상이 발생했습니다.

코드는 처음에 mac os에서 작성하였고 테스트할때는 별 문제 없었는데, linux로 코드를 옮기고 실행하니 위와 같은 문제가 갑자기 생겼습니다.

multiprocessing 모듈의 doc을 읽으면서 찾은것이 platform별로 process를 시작하는 방법이 3가지(spawn, fork, forkserver)가 있고,

platform별로 default 값이 다르다는것을 알았습니다.

제가 코드를 처음 작성했던 mac os와 window는 이 start method의 default 값이 'spawn'으로 되어있었는데, linux는 아마 'fork'로 설정이 돼있었던것 같습니다.

'fork'는 모든 process 마다 새로운 python interpreter를 시작하는 'spawn'과 달리 os.fork()를 사용하여 child process가 parent process의 resources들을 inherit 하는 method 인데, 이 과정에서 어떠한 충돌이 발생하여 프로그램이 막히는것 같습니다.

따라서 multiprocessing 모듈을 import 하는 스크립트에서 starting method를 'spawn'으로 설정하면서 문제를 해결할 수 있었습니다.

multiprocessing.set_start_method('spawn')

참고한 multiprocessing doc: https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant