{"id":2389,"date":"2017-03-24T15:10:14","date_gmt":"2017-03-24T06:10:14","guid":{"rendered":"http:\/\/daily.belltail.jp\/?p=2389"},"modified":"2017-03-25T13:24:45","modified_gmt":"2017-03-25T04:24:45","slug":"tqdm%e3%82%92%e3%83%a0%e3%83%aa%e3%83%a4%e3%83%aaprocess-safe%e3%81%ab%e3%81%99%e3%82%8b%e3%83%80%e3%83%bc%e3%83%86%e3%82%a3%e3%83%8f%e3%83%83%e3%82%af","status":"publish","type":"post","link":"https:\/\/daily.belltail.jp\/?p=2389","title":{"rendered":"tqdm\u3092\u30e0\u30ea\u30e4\u30eaprocess safe\u3063\u307d\u304f\u3059\u308bdirty hack"},"content":{"rendered":"<p>\u751f\u7269\u754c\u3067\u6700\u5927\u306e\u76ee\uff08\u5149\u3092\u691c\u77e5\u3059\u308b\u5668\u5b98\uff09\u3092\u6301\u3063\u3066\u3044\u308b\u306e\u306f\u30c0\u30a4\u30aa\u30a6\u30a4\u30ab\u304a\u3088\u3073\u30c0\u30a4\u30aa\u30a6\u30db\u30a6\u30ba\u30ad\u30a4\u30ab\u3068\u8a00\u308f\u308c\u3001\u305d\u306e\u5927\u304d\u3055\u306f30\u301c35cm\u307b\u3069\u306b\u3082\u306a\u308b\u306e\u3060\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u3055\u3066\u3001\u4e16\u754c70\u5104\u4eba\u306ePython\u30d7\u30ed\u30b0\u30e9\u30de\u304c\u624b\u653e\u305b\u306a\u3044\u306e\u304c\u3001tqdm\u3068\u3044\u3046\u30d7\u30ed\u30b0\u30ec\u30b9\u30d0\u30fc\u3092\u7c21\u5358\u306b\u8868\u793a\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u304f\u308c\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<br \/>\n\u3057\u304b\u3057\u306a\u304c\u3089tqdm\u306f\uff08\u5f53\u7136\u3068\u8a00\u3048\u3070\u5f53\u7136\u3067\u3059\u304c\uff09\u8907\u6570\u306e\u30d7\u30ed\u30bb\u30b9\u304b\u30891\u3064\u306e\u30d7\u30ed\u30b0\u30ec\u30b9\u30d0\u30fc\u3092\u7ba1\u7406\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306a\u8a2d\u8a08\u306b\u306f\u306a\u3063\u3066\u3044\u307e\u305b\u3093\u3002<br \/>\n\u305f\u3068\u3048\u3070\u9ad8\u901f\u5316\u306e\u305f\u3081\u306bmultiprocessing\u3092\u7528\u3044\u3066\u4e26\u5217\u51e6\u7406\u3092\u3057\u306a\u304c\u3089\u30d7\u30ed\u30b0\u30ec\u30b9\u30d0\u30fc\u3092\u51fa\u3057\u305f\u3044\u3068\u304d\u3001tqdm\u306f\u305d\u306e\u307e\u307e\u3067\u306f\u4f7f\u3048\u306a\u3044\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3067\u5358\u306btqdm\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u5b50\u30d7\u30ed\u30bb\u30b9\u306b\u6e21\u3057\u3066\u4e2d\u3067update\u3092\u3059\u308b\u3068\u2026<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport tqdm\r\nimport multiprocessing\r\n\r\ndef worker(pbar):\r\n    pbar.update()\r\n\r\nar = &#x5B;i for i in range(100)]\r\nwith tqdm.tqdm(ar) as pbar:\r\n    jobs = &#x5B;]\r\n    for t in ar:\r\n        job = multiprocessing.Process(target=worker, args=(pbar,))\r\n        job.start()\r\n        jobs.append(job)\r\n    for job in jobs:\r\n        job.join()\r\n<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\u306f\u3053\u3093\u306a\u611f\u3058\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n% python usage.py\r\n  1%|\u2589                                                                                                 | 1\/100 &#x5B;00:00&lt;00:25,  3.89it\/s]\r\n<\/pre>\n<p>\u3053\u3093\u306a\u3075\u3046\u306b\u3001100%\u307e\u3067\u884c\u3063\u3066\u304f\u308c\u307e\u305b\u3093\u3002<br \/>\n\u7aef\u7684\u306b\u8aac\u660e\u3059\u308b\u3068\u3001100\u500bfork\u3055\u308c\u305f\u5185\u90e8\u30ab\u30a6\u30f3\u30c80\u306e\u72b6\u614b\u3092\u305d\u308c\u305e\u308c+1\u3059\u308b\u306e\u304c100\u56de\u8d70\u308b\u3060\u3051\u3001\u3060\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u3058\u3083\u3042\u5185\u90e8\u30ab\u30a6\u30f3\u30c8\u304c\u5e38\u306b\u3088\u308d\u3057\u304f\u5897\u3048\u308b\u305f\u3081\u306b\u3001\u5185\u90e8\u30ab\u30a6\u30f3\u30c8\u3092\u7121\u8996\u3057\u3066\u5171\u6709\u30e1\u30e2\u30ea\u3067\u5e38\u306b\u6b63\u3057\u304f\u30ab\u30a6\u30f3\u30c8\u3057\u3066\u308c\u3070\u3044\u3044\u3088\u306d\u3001\u3063\u3066\u3044\u3046\u5358\u7d14\u306a\u767a\u60f3\u306b\u3088\u308b\u6c5a\u3044\u30cf\u30c3\u30af\u3092\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><!--more--><\/p>\n<p>** tqdm\u3092process safe\u3063\u307d\u304f\u3059\u308bdirty hack<\/p>\n<p>tqdm\u3092\u30e9\u30c3\u30d7\u3059\u308b\u30b3\u30fc\u30c9\uff08process_safe_tqdm.py\uff09\u304a\u3088\u3073\u305d\u308c\u3092\u4f7f\u3063\u3066multiprocessing\u304b\u3089\u4e26\u5217\u306b\u30ab\u30a6\u30f3\u30c8\u30a2\u30c3\u30d7\u3059\u308b\u30b3\u30fc\u30c9\uff08usage.py\uff09\u306f\u3053\u3061\u3089\u3002<br \/>\n\u306a\u304atqdm 4.11.2\u3001python 3.6.0\u3067\u52d5\u4f5c\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><script src=\"https:\/\/gist.github.com\/belltailjp\/5253066638ec76d97b085172b51356b3.js\"><\/script><\/p>\n<p>\u5b9f\u884c\u7d50\u679c\u306f\u3053\u3093\u306a\u304b\u3093\u3058\u3002\u3061\u3083\u3093\u3068100%\u307e\u3067\u884c\u3063\u3066\u304f\u308c\u308b\u3057\u3001\u753b\u9762\u306e\u7834\u7dbb\u7b49\u3082\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n% python usage.py\r\n100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 100\/100 &#x5B;00:00&lt;00:00, 343.01it\/s]\r\n<\/pre>\n<p>** \u89e3\u8aac<\/p>\n<p>\u57fa\u672c\u7684\u306b\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u6700\u521d\u306b\u8ff0\u3079\u305f\u3068\u304a\u308a\u3067\u3001<br \/>\n\u300ctqdm\u304c\u5185\u90e8\u306b\u6301\u3063\u3066\u3044\u308b\u30ab\u30a6\u30f3\u30c8\u3092\u7121\u8996\u3057\u3001\u30d7\u30ed\u30bb\u30b9\u9593\u5171\u6709\u5909\u6570\u306b\u57fa\u3065\u304f\u771f\u306e\u30ab\u30a6\u30f3\u30c8\u3092\u5225\u9014\u7528\u610f\u3057\u3066\u305d\u308c\u306b\u57fa\u3065\u3044\u3066\u30d7\u30ed\u30b0\u30ec\u30b9\u30d0\u30fc\u3092\u7ba1\u7406\u3059\u308b\u300d<br \/>\n\u3068\u3044\u3046\u8aac\u660e\u306b\u5c3d\u304d\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u3059\u308b\u305f\u3081\u3001update\u306e\u4e2d\u3067\u306f\u3001\u771f\u30ab\u30a6\u30f3\u30c8\u3067tqdm\u5185\u90e8\u30ab\u30a6\u30f3\u30c8\u3092\u5f37\u5236\u7684\u306b\u4e0a\u66f8\u304d\u3057\u305f\u3042\u3068\u753b\u9762\u306e\u66f4\u65b0\u3092\u3057\u3001\u305d\u306e\u5f8c\u771f\u306e\u30ab\u30a6\u30f3\u30c8\u3082\u66f4\u65b0\u3055\u305b\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u771f\u306e\u30ab\u30a6\u30f3\u30c8\u306b\u306f[https:\/\/docs.python.jp\/3\/library\/multiprocessing.html#multiprocessing.Value:title=multiprocessing.Value]\u3092\u4f7f\u3044\u307e\u3059\u3002\u753b\u9762\u306e\u7834\u7dbb\u3084\u771f\u306e\u30ab\u30a6\u30f3\u30c8\u306e\u30ba\u30ec\u3092\u9632\u3050\u305f\u3081\u3001multiprocess.Value\u306e\u6301\u3064\u30ed\u30c3\u30af\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u6392\u4ed6\u7684\u306b\u8d70\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>tqdm\u3067\u306f\u753b\u9762\u66f4\u65b0\u306e\u983b\u5ea6\u3092\u6291\u3048\u308b\u305f\u3081\u9069\u5f53\u306bupdate\u306e\u51e6\u7406\u3092\u7121\u8996\u3057\u3066\u3044\u308b\uff08[https:\/\/github.com\/tqdm\/tqdm\/blob\/v4.11.2\/tqdm\/_tqdm.py#L930:title=_tqdm.py#L930]\u306a\u3069\uff09\u306e\u3067\u3059\u304c\u3001\u4e00\u756a\u6700\u5f8c\u306f\u3061\u3083\u3093\u3068100%\u306b\u5230\u9054\u3055\u305b\u308b\u305f\u3081\u306e\u51e6\u7406\u304cclose\u306b\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\uff08[https:\/\/github.com\/tqdm\/tqdm\/blob\/v4.11.2\/tqdm\/_tqdm.py#L1023:title=_tqdm.py#L1023]\uff09\u3002<br \/>\n\u3053\u306e\u4e2d\u3067\u3082\u5185\u90e8\u30ab\u30a6\u30f3\u30c8\u3092\u547c\u3093\u3067\u308b\u306e\u3067\u3001\u6b63\u3057\u3044\u30ab\u30a6\u30f3\u30c8\u3067\u4e0a\u66f8\u304d\u3059\u308b\u3088\u3046close\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3059\u308b\u3053\u3068\u3067\u671f\u5f85\u901a\u308a\u52d5\u304f\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>** \u4f7f\u3048\u308b\u5834\u9762<\/p>\n<p>\u4e3b\u306bmultiprocessing\u3067\u91cd\u305f\u3044\u51e6\u7406\u3092\u6570\u5341\u301c\u6570\u767e\u5206\u5272\u3057\u5b50\u30d7\u30ed\u30bb\u30b9\u306b\u5206\u62c5\u3055\u305b\u308b\u5834\u5408\u306b\u4f7f\u3048\u307e\u3059\u3002\u30e9\u30c3\u30d1\u30fc\u5c0e\u5165\u306b\u3088\u308b\u30aa\u30fc\u30d0\u30d8\u30c3\u30c9\u304c\u3042\u308b\u306e\u30671\u30eb\u30fc\u30d7\u3042\u305f\u308a\u306e\u8a08\u7b97\u7c92\u5ea6\u3092\u5c0f\u3055\u304f\u3057\u3059\u304e\u306a\u3044\u3053\u3068\u306f\u5927\u4e8b\u3067\u3059\u304c\u3001\u305d\u308c\u3088\u308a\u306ffork\u3057\u3059\u304e\u308b\u3053\u3068\u306e\u30aa\u30fc\u30d0\u30d8\u30c3\u30c9\u306b\u6ce8\u610f\u3057\u3066\u3044\u308c\u3070OK\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u30e9\u30c3\u30d1\u30fc\u306ftqdm\u3092\u305d\u306e\u307e\u307e\u7f6e\u304d\u63db\u3048\u3066\u4f7f\u3048\u307e\u3059\uff08\u30b7\u30f3\u30b0\u30eb\u30d7\u30ed\u30bb\u30b9\u3067\u3082\u52d5\u304d\u307e\u3059\uff09\u3002\u7279\u306b\u3001update\u3092\u547c\u3070\u305a__iter__()\u3067\u547c\u3076\u5834\u5408\uff08[https:\/\/github.com\/tqdm\/tqdm#iterable-based:title=iterable based]\uff09\u306f\u3001tqdm\u3092\u76f4\u306b\u53e9\u3044\u3066\u3044\u308b\u306e\u3068\u5168\u304f\u540c\u3058\u3067\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u306f\u3042\u308a\u307e\u305b\u3093\u3002update\u3092\u53e9\u304f\u5834\u5408\uff08[https:\/\/github.com\/tqdm\/tqdm#manual:title=manual]\u3001\u30de\u30eb\u30c1\u30d7\u30ed\u30bb\u30b9\u5316\u3059\u308b\u5834\u5408\u306f\u3053\u3063\u3061\u306b\u306a\u308a\u307e\u3059\uff09\u3067\u30b7\u30f3\u30b0\u30eb\u30d7\u30ed\u30bb\u30b9\u306e\u5834\u5408\u306f\u30aa\u30fc\u30d0\u30d8\u30c3\u30c9\u3092\u907f\u3051\u3066tqdm\u3092\u76f4\u306b\u4f7f\u3046\u307b\u3046\u304c\u3044\u3044\u3067\u3059\u3002<\/p>\n<p>** \u6ce8\u610f<\/p>\n<p>tqdm\u306e\u30d0\u30fc\u306e\u53f3\u306b\u51fa\u3066\u304f\u308b\u30a4\u30c6\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u901f\u5ea6\u306f\u3001\u4fe1\u983c\u3067\u304d\u306a\u304f\u306a\u308a\u307e\u3059\u3002<br \/>\ntqdm\u304c\u5185\u90e8\u3067\u6301\u3063\u3066\u3044\u308b\u524d\u56de\u66f4\u65b0\u304b\u3089\u306e\u6642\u9593\u306b\u3064\u3044\u3066\u306f\u6b63\u3057\u304f\u7ba1\u7406\u3057\u3066\u3044\u306a\u3044\u305f\u3081\u3067\u3059\u3002<\/p>\n<p>joblib\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u3048\u308b\u3068\u3068\u3066\u3082\u4fbf\u5229\u306a\u306e\u3067\u3059\u304c\u3001tqdm\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304cpickle\u5316\u3067\u304d\u306a\u3044\uff08lambda\u3092\u3082\u3064\u306a\u3069\uff09\u305f\u3081\u3001\u6b8b\u5ff5\u306a\u304c\u3089\u4eca\u306e\u3068\u3053\u308d\u306f\u624b\u66f8\u304d\u3067\u30b4\u30ea\u30b4\u30ea\u3068multiprocessing\u3057\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u751f\u7269\u754c\u3067\u6700\u5927\u306e\u76ee\uff08\u5149\u3092\u691c\u77e5\u3059\u308b\u5668\u5b98\uff09\u3092\u6301\u3063\u3066\u3044\u308b\u306e\u306f\u30c0\u30a4\u30aa\u30a6\u30a4\u30ab\u304a\u3088\u3073\u30c0\u30a4\u30aa\u30a6\u30db\u30a6\u30ba\u30ad\u30a4\u30ab\u3068\u8a00\u308f\u308c\u3001\u305d\u306e\u5927\u304d\u3055\u306f30\u301c35cm\u307b\u3069\u306b\u3082\u306a\u308b\u306e\u3060\u305d\u3046\u3067\u3059\u3002 \u3055\u3066\u3001\u4e16\u754c70\u5104\u4eba\u306ePython\u30d7\u30ed\u30b0\u30e9\u30de\u304c\u624b\u653e\u305b\u306a\u3044\u306e\u304c\u3001tqd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[48,35,18,38,41],"class_list":["post-2389","post","type-post","status-publish","format-standard","hentry","category-1","tag-python","tag-35","tag-18","tag-38","tag-41"],"_links":{"self":[{"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/posts\/2389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2389"}],"version-history":[{"count":27,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/posts\/2389\/revisions"}],"predecessor-version":[{"id":2422,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/posts\/2389\/revisions\/2422"}],"wp:attachment":[{"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}