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

celery.task로 사용할 수 없는 문제 #65

Closed
comfuture opened this issue Jul 14, 2015 · 1 comment
Closed

celery.task로 사용할 수 없는 문제 #65

comfuture opened this issue Jul 14, 2015 · 1 comment

Comments

@comfuture
Copy link

comfuture commented Jul 14, 2015

celery task 함수 내에서 Kkma()등 자바기반 konlpy tag를 처음 init하는 경우 셀러리의 스레드 안에서 jvm_init()이 실행되어 정상적으로 jvm과 통신할 수 없게되는 문제가 있습니다.

다음의 celery task는 실패하고 영원히 끝나지 않습니다.

@celery.task
def record_nouns(score, sentence):
    t = Kkma()
    nouns = t.nouns(sentence)
    # TODO: save nouns to db
    return nouns

다음과 같이 module 스코프에서 인스턴스를 생성하는 방법으로 스레드내에서 jvm_init()이 되지 않도록 회피할 수 있습니다. 하지만 task를 call 하는 쪽 머신에도 konlpy를 설치해야 하거나 모듈을 import하는것만으로 불필요하게 무거운 jvm이 함께 실행되어야 하는 불편함이 있습니다.

t = Kkma()

@celery.task
def record_nouns(score, sentence):
    nouns = t.nouns(sentence)
    # TODO: save nouns to db
    return nouns

또는

from konlpy import jvm
jvm.init_jvm()

@celery.task
def record_nouns(score, sentence):
    # ...

스레드를 사용하는 많은 경우에 이같은 문제를 만날 가능성이 있으므로 스레드 밖에서 jvm을 시작할 수 있는 방법이 마련되면 좋을 것 같습니다.
감사합니다.

@e9t
Copy link
Member

e9t commented Nov 14, 2016

안녕하세요. 쓰레드를 여러 개 사용하는 경우 이 댓글을 참고해주시기 바랍니다.

@e9t e9t closed this as completed Nov 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants