{"id":2531,"date":"2019-12-24T01:22:17","date_gmt":"2019-12-23T16:22:17","guid":{"rendered":"https:\/\/www.white-room.jp\/blog\/?p=2531"},"modified":"2019-12-24T01:27:22","modified_gmt":"2019-12-23T16:27:22","slug":"popen%e3%81%ab%e5%8d%98%e7%b4%94%e3%81%ab%e6%8a%95%e3%81%92%e3%82%8b%e3%81%a8oom_killer%e3%81%ab%e6%ae%ba%e3%81%95%e3%82%8c%e3%82%8b%e3%81%93%e3%81%a8%e3%81%ab%e3%81%aa%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.white-room.jp\/blog\/?p=2531","title":{"rendered":"Popen\u306b\u5358\u7d14\u306b\u6295\u3052\u308b\u3068oom_killer\u306b\u6bba\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308b"},"content":{"rendered":"<p>1000\u679a\u7a0b\u5ea6\u306e\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u3092convert\u3067\u9069\u5f53\u306a\u51e6\u7406\u3092\u3084\u308b\u5de5\u7a0b\u3092python3\u306esubprocess\u3067<br \/>\n\u5358\u7d14\u306bfor\u3067\u56de\u3057\u3066<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfor file in files:\r\n  subprocess.Popen(&#x5B;convert\u3078\u306e\u30b3\u30de\u30f3\u30c9], cwd=dir)\r\n<\/pre>\n<p>\u307f\u305f\u3044\u306a\u611f\u3058\u3092OSX\u3067\u3084\u308b\u3068\u3001\u30e1\u30e2\u30ea\u3044\u3063\u3071\u3044\u307e\u3067\u98df\u3044\u3064\u3076\u3057\u3066\u6c17\u6301\u3061\u3044\u3044\u7206\u901f\u51e6\u7406\u304c\u3067\u304d\u307e\u3059\u3002\u4eee\u60f38\u30b3\u30a2100%\u3002CPU\u7a3c\u52d5\u7387\u306f\u3063\u3074\u3083\u304f\u3071\u30fc\u305b\u3093\u3068\uff01\u3000\u306a\u3093\u3060\u304b\u697d\u3057\u304f\u306a\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n<p>\u305d\u3093\u306a\u306b\u5165\u3089\u306a\u3044\u3043\u3043\u3043\u72b6\u614b\u307e\u3067\u98df\u308f\u305b\u308b\u306e\u3067\u3001\u5f53\u7136\u4ed6\u306e\u64cd\u4f5c\u306f\u51fa\u6765\u307e\u305b\u3093\u3002\u30d5\u30a1\u30f3\u304c\u3081\u3063\u305f\u306b\u306a\u3044\u9ad8\u901f\u56de\u8ee2\u306b\u306a\u308b\u306e\u304c\u6c17\u6301\u3061\u3044\u3044\u3002\u56de\u8ee2\u6570\u304c\u4e0b\u304c\u3063\u305f\u3089\u51e6\u7406\u304c\u7d42\u308f\u308a\u307f\u305f\u3044\u306a\u611f\u3058\u3002<\/p>\n<p>\u6295\u3052\u3063\u3071\u306a\u3057\u306a\u306e\u3067\u3001\u9069\u5f53\u306a\u624b\u6bb5\u3067\u6b21\u306e\u9010\u6b21\u51e6\u7406\u306b\u8ffd\u3044\u8d8a\u3055\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u306a\u3044\u3068\u3044\u3051\u307e\u305b\u3093\u304c\u3001OSX\u3067\u306f\u51e6\u7406\u524d\u30d5\u30a1\u30a4\u30eb\u3068\u51e6\u7406\u5f8c\u30d5\u30a1\u30a4\u30eb\u306e\u6570\u3092\u6bd4\u8f03\u3057\u3066\u3001\u5408\u308f\u306a\u304b\u3063\u305f\u3089\u5bdd\u3066\u308d\u3067\u6b62\u3081\u3089\u308c\u307e\u3059\u3002\u66f8\u304d\u51fa\u3057\u4e2d\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u30ab\u30a6\u30f3\u30c8\u3057\u306a\u3044\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092Linux\u3067\u3084\u308b\u3068\u4e88\u5b9a\u901a\u308a\u3001oom_killer\u306b\u6bba\u3055\u308c\u3066\u30b7\u30b9\u30c6\u30e0\u81ea\u4f53\u304c\u52d5\u4f5c\u4e0d\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3069\u3053\u3067\u3082\u52d5\u304f\u5236\u9650\u4ed8\u304d\u306e\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u306b\u5909\u66f4\u305b\u306d\u3070\u2026\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n\u300c\u30d5\u30a9\u30eb\u30c01\u300d\u306btiff\u30d5\u30a1\u30a4\u30eb\u304c\u5165\u3063\u3066\u3044\u3066\u3001\u51e6\u7406\u6e08\u307f\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u300c\u30d5\u30a9\u30eb\u30c02\u300d\u306b\u66f8\u304d\u51fa\u3059\u51e6\u7406\u3002\r\n\r\ndef hage(x):\r\n    subprocess.check_output(&#x5B;'convert'---x&#x5B;n]\u3092\u9069\u5f53\u306b\u5f53\u3066\u306f\u3081\u3066\u30b3\u30de\u30f3\u30c9\u3092\u5f62\u6210--], cwd='.\/'--\u30ab\u30ec\u30f3\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u8d70\u3089\u305b\u308b\u6c7a\u3081\u6253\u3061)\r\n\r\ndef main():\r\n    todo_list = &#x5B;]\r\n    for file in files:\r\n        todo_list.append(\u30d5\u30a9\u30fc\u30eb\u30fc\u30d7\u3067\u56de\u3059\u306e\u306b\u4f7f\u3046\u306f\u305a\u3060\u3063\u305f\u5909\u6570\u4e00\u89a7\uff09\r\n        # \u3053\u3053\u3067\u8aad\u307f\u8fbc\u307f\u30d5\u30a1\u30a4\u30eb\u306e\u30d5\u30eb\u30d1\u30b9\u3068\u66f8\u304d\u51fa\u3057\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u30ea\u30b9\u30c8\u3092\u4f5c\u308b\u306e\u3067\u9806\u4e0d\u540c\u306b\u51e6\u7406\u3055\u308c\u3066\u3082\u554f\u984c\u306a\u3057\r\n    p = Pool(\u3044\u3044\u5869\u6885\u306a\u30d7\u30ed\u30bb\u30b9\u5236\u9650\u306e\u6570\u5024\uff09\r\n    p.map(hage, todo_list)\r\n<\/pre>\n<p>check_output\u306esubprocess\u304cPool()\u500b\u3065\u3064\u56de\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u3067\u3001\u307e\u305fPopen\u3092\u4f7f\u3063\u3066\u3057\u307e\u3046\u3068\u3001\u623b\u308a\u304c\u306a\u3044\u306e\u3067\u3001\u3072\u305f\u3059\u3089\u3076\u3063\u3053\u307e\u308c\u3066\u6700\u521d\u306b\u623b\u308b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>6.2MB\u306eTiff\u30d5\u30a1\u30a4\u30eb\u3092200\u679a\u306e\u51e6\u7406\u3067\u3001\u5358\u7d14\u306bcheck_output\u306b\u6295\u3052\u308b\u3068\u30011\u30d5\u30a1\u30a4\u30eb\u305a\u3064\u306e\u51e6\u7406\u306b\u306a\u308b\u306e\u3067\u7d04280\u79d2\u3002Pool(8)\u3061\u3083\u3093\u306b\u56de\u3057\u3066\u3082\u3089\u3046\u3068\u3001\u7d0460\u79d2\u3002<\/p>\n<p>\u5358\u7d14\u306bPopen\u306b\u6295\u3052\u305f\u3068\u304d\u3088\u308a\u5c11\u3057\u3060\u3051\u901f\u304b\u3063\u305f\u306e\u3067\u3001\u3061\u3087\u3063\u3068\u3073\u3063\u304f\u308a\u3002<\/p>\n<p>\u98df\u3044\u3064\u3076\u3055\u308c\u3066\u3082\u6b7b\u306a\u306a\u3044\u3088\u3046\u306bOSX\u304c\u306a\u3093\u304b\u3057\u3066\u308b\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u7684\u306a\u4f55\u304b\u304c\u306a\u304f\u306a\u308a\u3001\u8ad6\u7406\u30b3\u30a2\u6570\u5206\uff08\u3046\u3061\u306e\u306f4\u30b3\u30a2\u3002\u8ad6\u74068\u30b3\u30a2\uff09\u306e\u30d7\u30ed\u30bb\u30b9\u3057\u304b\u4f7f\u308f\u306a\u3044\u306e\u3067\u304a\u6c17\u697d\u306b\u306a\u308b\u306e\u3060\u3068\u601d\u308f\u308c\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1000\u679a\u7a0b\u5ea6\u306e\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u3092convert\u3067\u9069\u5f53\u306a\u51e6\u7406\u3092\u3084\u308b\u5de5\u7a0b\u3092python3\u306esubprocess\u3067 \u5358\u7d14\u306bfor\u3067\u56de\u3057\u3066 for file in files: subprocess.Popen(&#x5B;con [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-2531","post","type-post","status-publish","format-standard","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.white-room.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.white-room.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.white-room.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.white-room.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.white-room.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2531"}],"version-history":[{"count":3,"href":"https:\/\/www.white-room.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2531\/revisions"}],"predecessor-version":[{"id":2546,"href":"https:\/\/www.white-room.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2531\/revisions\/2546"}],"wp:attachment":[{"href":"https:\/\/www.white-room.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.white-room.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.white-room.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}