{"action":"created","issue":{"url":"https://api.github.com/repos/konlpy/konlpy/issues/65","repository_url":"https://api.github.com/repos/konlpy/konlpy","labels_url":"https://api.github.com/repos/konlpy/konlpy/issues/65/labels{/name}","comments_url":"https://api.github.com/repos/konlpy/konlpy/issues/65/comments","events_url":"https://api.github.com/repos/konlpy/konlpy/issues/65/events","html_url":"https://github.com/konlpy/konlpy/issues/65","id":94852434,"number":65,"title":"celery.task로 사용할 수 없는 문제","user":{"login":"comfuture","id":151300,"avatar_url":"https://avatars.githubusercontent.com/u/151300?v=3","gravatar_id":"","url":"https://api.github.com/users/comfuture","html_url":"https://github.com/comfuture","followers_url":"https://api.github.com/users/comfuture/followers","following_url":"https://api.github.com/users/comfuture/following{/other_user}","gists_url":"https://api.github.com/users/comfuture/gists{/gist_id}","starred_url":"https://api.github.com/users/comfuture/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/comfuture/subscriptions","organizations_url":"https://api.github.com/users/comfuture/orgs","repos_url":"https://api.github.com/users/comfuture/repos","events_url":"https://api.github.com/users/comfuture/events{/privacy}","received_events_url":"https://api.github.com/users/comfuture/received_events","type":"User","site_admin":false},"labels":[{"id":107040890,"url":"https://api.github.com/repos/konlpy/konlpy/labels/jpype","name":"jpype","color":"eb6420","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2015-07-14T02:17:52Z","updated_at":"2016-11-14T14:26:54Z","closed_at":"2016-11-14T14:26:54Z","body":"celery task 함수 내에서 Kkma()등 자바기반 konlpy tag를 처음 init하는 경우 셀러리의 스레드 안에서 jvm_init()이 실행되어 정상적으로 jvm과 통신할 수 없게되는 문제가 있습니다.\n\n다음의 celery task는 실패하고 영원히 끝나지 않습니다.\n\n``` python\n@celery.task\ndef record_nouns(score, sentence):\n    t = Kkma()\n    nouns = t.nouns(sentence)\n    # TODO: save nouns to db\n    return nouns\n```\n\n다음과 같이 module 스코프에서 인스턴스를 생성하는 방법으로 스레드내에서 jvm_init()이 되지 않도록 회피할 수 있습니다. 하지만 task를 call 하는 쪽 머신에도 konlpy를 설치해야 하거나 모듈을 import하는것만으로 불필요하게 무거운 jvm이 함께 실행되어야 하는 불편함이 있습니다.\n\n``` python\nt = Kkma()\n\n@celery.task\ndef record_nouns(score, sentence):\n    nouns = t.nouns(sentence)\n    # TODO: save nouns to db\n    return nouns\n```\n\n또는\n\n``` python\nfrom konlpy import jvm\njvm.init_jvm()\n\n@celery.task\ndef record_nouns(score, sentence):\n    # ...\n```\n\n스레드를 사용하는 많은 경우에 이같은 문제를 만날 가능성이 있으므로 스레드 밖에서 jvm을 시작할 수 있는 방법이 마련되면 좋을 것 같습니다.\n감사합니다.\n## \n\r\n\r\n<bountysource-plugin>\r\n---\r\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/24291799-celery-task?utm_campaign=plugin&utm_content=tracker%2F1743549&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F1743549&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"},"comment":{"url":"https://api.github.com/repos/konlpy/konlpy/issues/comments/260347959","html_url":"https://github.com/konlpy/konlpy/issues/65#issuecomment-260347959","issue_url":"https://api.github.com/repos/konlpy/konlpy/issues/65","id":260347959,"user":{"login":"e9t","id":1205890,"avatar_url":"https://avatars.githubusercontent.com/u/1205890?v=3","gravatar_id":"","url":"https://api.github.com/users/e9t","html_url":"https://github.com/e9t","followers_url":"https://api.github.com/users/e9t/followers","following_url":"https://api.github.com/users/e9t/following{/other_user}","gists_url":"https://api.github.com/users/e9t/gists{/gist_id}","starred_url":"https://api.github.com/users/e9t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/e9t/subscriptions","organizations_url":"https://api.github.com/users/e9t/orgs","repos_url":"https://api.github.com/users/e9t/repos","events_url":"https://api.github.com/users/e9t/events{/privacy}","received_events_url":"https://api.github.com/users/e9t/received_events","type":"User","site_admin":false},"created_at":"2016-11-14T14:26:54Z","updated_at":"2016-11-14T14:26:54Z","body":"안녕하세요. 쓰레드를 여러 개 사용하는 경우 [이 댓글](https://github.com/konlpy/konlpy/issues/85#issuecomment-260345690)을 참고해주시기 바랍니다."}}
{"actor":{"display_login":"e9t"}}