{"id":109557,"date":"2026-09-24T12:49:38","date_gmt":"2026-09-24T04:49:38","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/109557.html"},"modified":"2026-09-24T12:49:38","modified_gmt":"2026-09-24T04:49:38","slug":"ray-%e7%9a%84-remote-%e8%b0%83%e7%94%a8%e4%b9%8b%e5%90%8e%ef%bc%9a%e4%bb%bb%e5%8a%a1%e6%80%8e%e6%a0%b7%e8%a1%94%e6%8e%a5%ef%bc%8c%e7%8a%b6%e6%80%81%e7%95%99%e5%9c%a8%e5%93%aa%e9%87%8c","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/109557.html","title":{"rendered":"Ray \u7684 remote \u8c03\u7528\u4e4b\u540e\uff1a\u4efb\u52a1\u600e\u6837\u8854\u63a5\uff0c\u72b6\u6001\u7559\u5728\u54ea\u91cc?"},"content":{"rendered":"<h2>Ray \u7684 remote \u8c03\u7528\u4e4b\u540e&#xff1a;\u4efb\u52a1\u600e\u6837\u8854\u63a5&#xff0c;\u72b6\u6001\u7559\u5728\u54ea\u91cc<\/h2>\n<p>\u628a\u4e00\u6279\u6587\u672c\u7684\u9884\u5904\u7406\u51fd\u6570\u52a0\u4e0a &#064;ray.remote&#xff0c;\u518d\u9010\u6761\u8c03\u7528&#xff0c;\u7a0b\u5e8f\u770b\u8d77\u6765\u5df2\u7ecf\u201c\u5206\u5e03\u5f0f\u5316\u201d\u3002\u4f46\u4e0b\u9762\u8fd9\u4e2a\u5faa\u73af\u4ecd\u7136\u662f\u4e00\u4efd\u5de5\u4f5c\u7ed3\u675f&#xff0c;\u624d\u63d0\u4ea4\u4e0b\u4e00\u4efd&#xff1a;<\/p>\n<p><span class=\"token keyword\">for<\/span> text <span class=\"token keyword\">in<\/span> texts<span class=\"token punctuation\">:<\/span><br \/>\n    value <span class=\"token operator\">&#061;<\/span> ray<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span>prepare<span class=\"token punctuation\">.<\/span>remote<span class=\"token punctuation\">(<\/span>text<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    consume<span class=\"token punctuation\">(<\/span>value<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u5373\u4f7f\u53e6\u4e00\u4e2a Worker \u7a7a\u95f2&#xff0c;\u5b83\u4e5f\u65e0\u6cd5\u63d0\u524d\u5904\u7406\u4e0b\u4e00\u6761&#xff1a;Driver\u2014\u2014\u63d0\u4ea4\u8fd9\u4e9b\u8c03\u7528\u7684\u5e94\u7528\u8fdb\u7a0b\u2014\u2014\u8fd8\u505c\u5728\u4e0a\u4e00\u6761\u7684 ray.get\u3002\u8fd9\u4e2a\u95ee\u9898\u4e0d\u9700\u8981\u5148\u7814\u7a76\u96c6\u7fa4\u90e8\u7f72&#xff0c;\u8bfb\u61c2\u4e00\u6bb5\u8c03\u7528\u4ee3\u7801\u5c31\u80fd\u53d1\u73b0\u3002<\/p>\n<p>Ray Core \u63d0\u4f9b\u8fdc\u7a0b\u4efb\u52a1\u3001\u7ed3\u679c\u5f15\u7528\u548c\u6709\u72b6\u6001\u6267\u884c\u8fdb\u7a0b\u3002\u7406\u89e3\u5b83\u7684\u8d77\u70b9&#xff0c;\u662f\u5206\u6e05\u63d0\u4ea4\u5de5\u4f5c\u3001\u7b49\u5f85\u4f9d\u8d56\u3001\u53d6\u5f97\u7ed3\u679c\u3001\u4fee\u6539\u72b6\u6001\u53d1\u751f\u5728\u54ea\u91cc\u3002\u672c\u6587\u56f4\u7ed5\u6587\u672c\u9884\u5904\u7406\u4e0e\u8bc4\u5206\u7684\u77ed\u6d41\u7a0b\u5c55\u5f00&#xff1b;\u793a\u4f8b\u4e0d\u52a0\u8f7d\u6a21\u578b&#xff0c;\u6ca1\u6709 GPU\u3001\u541e\u5410\u6216\u6545\u969c\u5b9e\u6d4b\u3002\u63a5\u53e3\u8bed\u4e49\u4f9d\u636e 2026 \u5e74 9 \u6708 9 \u65e5\u6838\u5bf9\u7684 Ray 2.58.0 \u5b98\u65b9\u6587\u6863\u3002<\/p>\n<h3>\u4e0b\u4e00\u4efd\u4efb\u52a1\u4ec0\u4e48\u65f6\u5019\u624d\u88ab\u63d0\u4ea4<\/h3>\n<p>prepare.remote(text) \u63d0\u4ea4\u4e00\u6b21 Task&#xff0c;\u901a\u5e38\u8fd4\u56de\u4ee3\u8868\u672a\u6765\u7ed3\u679c\u7684 ObjectRef&#xff1b;\u8fd9\u65f6\u7ed3\u679c\u672a\u5fc5\u5df2\u7ecf\u4ea7\u751f\u3002ray.get(ref) \u624d\u5728\u8c03\u7528\u65b9\u7b49\u5f85\u5e76\u53d6\u5f97\u503c\u3002\u4efb\u52a1\u4e5f\u4e0d\u4e00\u5b9a\u6bcf\u6b21\u65b0\u5efa\u8fdb\u7a0b&#xff0c;Ray \u53ef\u4ee5\u590d\u7528 Worker \u6267\u884c\u591a\u6b21\u666e\u901a Task\u3002<\/p>\n<p>\u539f\u5faa\u73af\u628a\u63d0\u4ea4\u4e0e\u7b49\u5f85\u7ed1\u5728\u540c\u4e00\u8f6e\u3002\u82e5\u6587\u672c\u4e92\u76f8\u72ec\u7acb&#xff0c;\u53ef\u4ee5\u5148\u4fdd\u7559\u5f15\u7528&#xff0c;\u6700\u540e\u6536\u53d6\u7ed3\u679c&#xff1a;<\/p>\n<p>refs <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span>prepare<span class=\"token punctuation\">.<\/span>remote<span class=\"token punctuation\">(<\/span>text<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">for<\/span> text <span class=\"token keyword\">in<\/span> texts<span class=\"token punctuation\">]<\/span><br \/>\nvalues <span class=\"token operator\">&#061;<\/span> ray<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span>refs<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd9\u53ea\u662f\u6253\u5f00\u4e86\u4efb\u52a1\u91cd\u53e0\u6267\u884c\u7684\u673a\u4f1a\u3002\u80fd\u540c\u65f6\u8fd0\u884c\u591a\u5c11\u4efd&#xff0c;\u4ecd\u53d6\u51b3\u4e8e\u8d44\u6e90\u4e0e\u8c03\u5ea6&#xff1b;\u51fd\u6570\u592a\u7ec6\u3001\u4f20\u8f93\u592a\u91cd\u65f6&#xff0c;\u4e5f\u53ef\u80fd\u5f97\u4e0d\u507f\u5931\u3002\u5b83\u6ca1\u6709\u7ed9\u51fa\u4efb\u4f55\u52a0\u901f\u500d\u6570\u3002<\/p>\n<p>Ray \u7684\u5faa\u73af\u5185 get \u53cd\u4f8b\u76f4\u63a5\u5bf9\u6bd4\u4e86\u8fd9\u4e24\u79cd\u5199\u6cd5\u3002\u5173\u952e\u8bc1\u636e\u5728\u63d0\u4ea4\u4f4d\u7f6e&#xff1a;\u7b2c\u4e00\u79cd\u5199\u6cd5\u7b49\u5f85\u524d\u4e00\u4e2a\u7ed3\u679c&#xff0c;\u7b2c\u4e8c\u79cd\u5728\u7b49\u5f85\u4e4b\u524d\u5df2\u63d0\u4ea4\u4e00\u6279\u5de5\u4f5c\u3002\u5bf9\u4e8e\u672c\u6765\u5c31\u6709\u5148\u540e\u4f9d\u8d56\u7684\u4e1a\u52a1&#xff0c;\u4e0d\u80fd\u7167\u642c\u5e76\u53d1\u6539\u5199&#xff1b;\u72ec\u7acb\u6027\u5fc5\u987b\u6765\u81ea\u4e1a\u52a1\u672c\u8eab\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u79cd\u5bb9\u6613\u6df7\u6dc6\u7684\u5199\u6cd5&#xff1a;\u5df2\u7ecf\u63d0\u4ea4\u5b8c\u5168\u90e8\u4efb\u52a1&#xff0c;\u518d\u6309\u7167\u5f15\u7528\u5217\u8868\u9010\u4e2a get\u3002\u6b64\u65f6\u540e\u53f0\u5de5\u4f5c\u4ecd\u6709\u673a\u4f1a\u5e76\u884c&#xff0c;\u53ea\u662f\u8c03\u7528\u65b9\u53ef\u80fd\u7b49\u7740\u6392\u5728\u524d\u9762\u7684\u6162\u4efb\u52a1&#xff0c;\u8fdf\u8fdf\u4e0d\u5904\u7406\u540e\u9762\u5df2\u5b8c\u6210\u7684\u7ed3\u679c\u3002\u5b83\u4e0e\u201c\u4e0b\u4e00\u4efd\u4efb\u52a1\u6839\u672c\u6ca1\u6709\u63d0\u4ea4\u201d\u662f\u4e24\u79cd\u963b\u585e\u3002\u7ed3\u679c\u53ef\u72ec\u7acb\u6d88\u8d39\u65f6&#xff0c;\u53ef\u4ee5\u7528 ray.wait \u53d6\u56de\u5df2\u5c31\u7eea\u7684\u5f15\u7528&#xff1b;\u5982\u679c\u5fc5\u987b\u6309\u8f93\u5165\u987a\u5e8f\u8f93\u51fa&#xff0c;\u5c31\u8981\u4fdd\u5b58\u5e8f\u53f7\u5e76\u627f\u62c5\u91cd\u6392\u7f13\u51b2&#xff0c;\u4e0d\u80fd\u5047\u88c5\u987a\u5e8f\u8981\u6c42\u5df2\u7ecf\u6d88\u5931\u3002\u5b98\u65b9\u7ed3\u679c\u5904\u7406\u53cd\u4f8b\u8ba8\u8bba\u7684\u6b63\u662f\u8fd9\u4e00\u5dee\u522b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260924044927-6ab4abd7f00c4.png\" alt=\"\u56fe01\" \/> <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260924044930-6ab4abda68d6b.png\" alt=\"\u56fe02\" \/><\/p>\n<h3>ObjectRef \u628a\u4f9d\u8d56\u4ea4\u7ed9\u4e0b\u6e38&#xff0c;\u6570\u636e\u4ecd\u8981\u5230\u8fbe<\/h3>\n<p>\u9884\u5904\u7406\u540e\u8fd8\u6709\u8bc4\u5206\u9636\u6bb5\u3002\u6700\u76f4\u63a5\u7684\u5199\u6cd5\u662f\u5728 Driver \u53d6\u56de\u9884\u5904\u7406\u7ed3\u679c&#xff0c;\u518d\u63d0\u4ea4\u8bc4\u5206&#xff1a;<\/p>\n<p>prepared <span class=\"token operator\">&#061;<\/span> ray<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span>prepare<span class=\"token punctuation\">.<\/span>remote<span class=\"token punctuation\">(<\/span>text<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\nscore_ref <span class=\"token operator\">&#061;<\/span> score<span class=\"token punctuation\">.<\/span>remote<span class=\"token punctuation\">(<\/span>prepared<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u5982\u679c Driver \u4e0d\u9700\u8981\u67e5\u770b\u4e2d\u95f4\u503c&#xff0c;\u53ef\u4ee5\u628a\u5f15\u7528\u4f5c\u4e3a\u8bc4\u5206\u8c03\u7528\u7684\u9876\u5c42\u53c2\u6570&#xff1a;<\/p>\n<p>prepared_ref <span class=\"token operator\">&#061;<\/span> prepare<span class=\"token punctuation\">.<\/span>remote<span class=\"token punctuation\">(<\/span>text<span class=\"token punctuation\">)<\/span><br \/>\nscore_ref <span class=\"token operator\">&#061;<\/span> score<span class=\"token punctuation\">.<\/span>remote<span class=\"token punctuation\">(<\/span>prepared_ref<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u7b2c\u4e8c\u4e2a\u8c03\u7528\u53ef\u4ee5\u5148\u63d0\u4ea4\u3002Ray \u7b49\u9876\u5c42\u5f15\u7528\u5bf9\u5e94\u7684\u6570\u636e\u53ef\u7528&#xff0c;\u518d\u6267\u884c score&#xff0c;\u51fd\u6570\u63a5\u6536\u7684\u662f\u5df2\u7ecf\u89e3\u5f00\u7684\u503c\u3002\u7b49\u5f85\u5e76\u6ca1\u6709\u6d88\u5931&#xff0c;\u800c\u662f\u4ece Driver \u624b\u52a8\u963b\u585e&#xff0c;\u53d8\u6210\u4e86\u8fd0\u884c\u65f6\u77e5\u9053\u7684\u4efb\u52a1\u4f9d\u8d56\u3002\u8fd9\u8ba9 Driver \u80fd\u7ee7\u7eed\u63d0\u4ea4\u5176\u4ed6\u72ec\u7acb\u6587\u672c\u7684\u5904\u7406\u94fe\u3002<\/p>\n<p>\u4f20\u53c2\u7684\u5c42\u7ea7\u4f1a\u6539\u53d8\u542b\u4e49\u3002score.remote([prepared_ref]) \u628a\u5f15\u7528\u85cf\u8fdb\u5217\u8868&#xff0c;Ray \u4e0d\u4f1a\u81ea\u52a8\u628a\u5b83\u89e3\u6210\u503c\u5217\u8868&#xff1b;\u88ab\u8c03\u7528\u51fd\u6570\u62ff\u5230\u7684\u662f\u5305\u542b\u5f15\u7528\u7684\u5217\u8868\u3002\u5982\u679c\u5b83\u8981\u8bfb\u503c&#xff0c;\u9700\u8981\u663e\u5f0f\u53d6\u56de\u3002\u82e5\u53ea\u8d1f\u8d23\u628a\u5f15\u7528\u8f6c\u4ea4\u7ed9\u5176\u4ed6\u4efb\u52a1&#xff0c;\u4e5f\u53ef\u4ee5\u59cb\u7ec8\u4e0d\u8bfb\u6570\u636e\u3002Ray Objects\u660e\u786e\u533a\u5206\u8fd9\u4e24\u79cd\u884c\u4e3a&#xff0c;Actor \u6784\u9020\u51fd\u6570\u548c\u65b9\u6cd5\u8c03\u7528\u4e5f\u91c7\u7528\u8fd9\u4e2a\u7ea6\u5b9a\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u7ed9\u4e0b\u6e38\u4f20\u4e00\u4e2a\u5b57\u5178\u6216\u5217\u8868\u4e4b\u524d&#xff0c;\u8981\u786e\u8ba4\u63a5\u53e3\u7ea6\u5b9a\u7684\u662f\u5b9e\u9645\u503c&#xff0c;\u8fd8\u662f\u4f9b\u7ee7\u7eed\u8f6c\u4ea4\u7684\u5f15\u7528\u3002\u4e24\u8005\u90fd\u5408\u7406&#xff0c;\u4f46\u4e0d\u80fd\u53ea\u6539\u5bb9\u5668\u5f62\u72b6\u800c\u4fdd\u7559\u539f\u5148\u7684\u51fd\u6570\u7406\u89e3\u3002\u4e0a\u6e38\u5931\u8d25\u65f6&#xff0c;\u4e5f\u4e0d\u80fd\u628a\u201c\u624b\u91cc\u6709 ObjectRef\u201d\u5f53\u6210\u7ed3\u679c\u5b58\u5728&#xff1b;\u6700\u7ec8\u7b49\u5f85\u6216\u8bfb\u53d6\u7ed3\u679c\u4ecd\u53ef\u80fd\u5f97\u5230\u5f02\u5e38\u3002<\/p>\n<p>\u5f15\u7528\u4e5f\u4e0d\u7b49\u4e8e\u6ca1\u6709\u6570\u636e\u6210\u672c\u3002\u5bf9\u8c61\u53ef\u80fd\u4f4d\u4e8e\u5176\u4ed6\u8282\u70b9&#xff0c;\u4f7f\u7528\u5b83\u4ecd\u53ef\u80fd\u9700\u8981\u4f20\u8f93&#xff1b;\u5bf9\u8c61\u5b58\u50a8\u4e2d\u7684\u8fdc\u7a0b\u5bf9\u8c61\u662f\u4e0d\u53ef\u53d8\u7684&#xff0c;\u4e0d\u80fd\u4f5c\u4e3a\u5404\u8fdb\u7a0b\u968f\u610f\u4fee\u6539\u7684\u5171\u4eab Python \u53d8\u91cf\u3002\u8fd9\u91cc\u8ba8\u8bba\u7684\u662f\u666e\u901a Ray Core \u5bf9\u8c61\u673a\u5236&#xff0c;\u4e0d\u4ece\u5f15\u7528\u4f20\u9012\u63a8\u5bfc GPU Tensor \u96f6\u62f7\u8d1d&#xff0c;\u4e5f\u4e0d\u628a\u672a\u542f\u7528\u7684\u4e13\u7528\u4f20\u8f93\u673a\u5236\u7b97\u8fdb\u6536\u76ca\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260924044931-6ab4abdb7a8fb.png\" alt=\"\u56fe03\" \/><\/p>\n<h3>Actor \u7559\u4f4f\u72b6\u6001&#xff0c;\u4e5f\u9650\u5b9a\u4e86\u8c03\u7528\u843d\u5728\u54ea\u4e2a\u8fdb\u7a0b<\/h3>\n<p>\u5982\u679c\u8bc4\u5206\u9700\u8981\u53cd\u590d\u4f7f\u7528\u540c\u4e00\u4efd\u5df2\u52a0\u8f7d\u6a21\u578b&#xff0c;\u628a\u52a0\u8f7d\u52a8\u4f5c\u5199\u5728\u6bcf\u6b21 Task \u5185\u90e8&#xff0c;\u53ef\u80fd\u91cd\u590d\u505a\u6602\u8d35\u521d\u59cb\u5316\u3002Actor \u4e3a\u53e6\u4e00\u79cd\u7ec4\u7ec7\u65b9\u5f0f\u63d0\u4f9b\u4e86\u57fa\u7840&#xff1a;\u521b\u5efa\u4e00\u4e2a\u6709\u72b6\u6001 Worker&#xff0c;\u628a\u540e\u7eed\u65b9\u6cd5\u8c03\u7528\u4ea4\u7ed9\u5b83&#xff0c;\u5728\u5176\u751f\u547d\u5468\u671f\u5185\u590d\u7528\u6210\u5458\u53d8\u91cf\u3002<\/p>\n<p>\u4e3a\u4e86\u53ea\u89c2\u5bdf\u8fd9\u4e00\u70b9&#xff0c;\u4e0b\u9762\u7528\u5b57\u7b26\u6570\u4ee3\u66ff\u6a21\u578b\u8bc4\u5206&#xff0c;\u7528\u8ba1\u6570\u5668\u4ee3\u8868\u8fdb\u7a0b\u5185\u72b6\u6001&#xff1a;<\/p>\n<p><span class=\"token decorator annotation punctuation\">&#064;ray<span class=\"token punctuation\">.<\/span>remote<\/span><span class=\"token punctuation\">(<\/span>num_cpus<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Scorer<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>processed <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">score<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> item<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        request_id<span class=\"token punctuation\">,<\/span> text <span class=\"token operator\">&#061;<\/span> item<br \/>\n        self<span class=\"token punctuation\">.<\/span>processed <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token number\">1<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> request_id<span class=\"token punctuation\">,<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>text<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> self<span class=\"token punctuation\">.<\/span>processed<\/p>\n<p>Scorer.remote() \u8fd4\u56de Actor \u53e5\u67c4&#xff0c;scorer.score.remote(item) \u8fd4\u56de\u8fd9\u6b21\u65b9\u6cd5\u8c03\u7528\u7684\u7ed3\u679c\u5f15\u7528\u3002\u53e5\u67c4\u7528\u6765\u627e\u5230\u6709\u72b6\u6001\u6267\u884c\u5bf9\u8c61&#xff1b;\u7ed3\u679c\u5f15\u7528\u7528\u6765\u627e\u5230\u67d0\u6b21\u8c03\u7528\u7684\u8fd4\u56de\u503c\u3002\u628a\u4e24\u8005\u90fd\u7406\u89e3\u6210\u201c\u8fdc\u7a0b\u7ed3\u679c\u201d&#xff0c;\u5c31\u5bb9\u6613\u8bef\u628a\u521b\u5efa\u5b9e\u4f8b\u5f53\u6210\u5df2\u7ecf\u83b7\u5f97\u8bc4\u5206\u3002<\/p>\n<p>Actors \u6587\u6863\u8bf4\u660e&#xff0c;\u6bcf\u4e2a Python Actor \u5728\u81ea\u5df1\u7684\u8fdb\u7a0b\u4e2d\u8fd0\u884c&#xff0c;\u65b9\u6cd5\u53ef\u4ee5\u8bbf\u95ee\u548c\u4fee\u6539\u8be5 Worker \u7684\u72b6\u6001\u3002\u521b\u5efa\u4e24\u4e2a Actor&#xff0c;\u610f\u5473\u7740\u4e24\u4efd\u5404\u81ea\u6301\u6709\u7684\u6210\u5458\u72b6\u6001&#xff0c;\u4e0d\u4f1a\u81ea\u52a8\u53d8\u6210\u4e00\u4e2a\u5171\u4eab\u8ba1\u6570\u5668\u3002\u771f\u5b9e\u6a21\u578b\u653e\u8fdb\u6210\u5458\u53d8\u91cf&#xff0c;\u4e5f\u53ea\u662f\u8ba9\u5b83\u5728\u8be5\u5b9e\u4f8b\u751f\u547d\u5468\u671f\u5185\u590d\u7528&#xff1b;\u4e0d\u4f1a\u56e0\u6b64\u81ea\u52a8\u5207\u5206\u6743\u91cd\u6216\u8de8\u5b9e\u4f8b\u5171\u4eab\u663e\u5b58\u3002<\/p>\n<p>\u8fd9\u4e00\u4f8b\u91c7\u7528\u540c\u6b65\u3001\u5355\u7ebf\u7a0b Actor\u3002\u540c\u4e00\u63d0\u4ea4\u8005\u53d1\u6765\u7684\u65b9\u6cd5&#xff0c;\u9ed8\u8ba4\u6309\u63d0\u4ea4\u987a\u5e8f\u6267\u884c&#xff1b;\u5373\u4f7f Driver \u5f88\u5feb\u63d0\u4ea4\u5341\u6b21 .score.remote()&#xff0c;\u8fd9\u4e2a Actor \u4e5f\u4e0d\u4f1a\u81ea\u52a8\u540c\u65f6\u8dd1\u5341\u6b21\u8bc4\u5206\u3002\u82e5\u524d\u4e00\u4e2a\u8c03\u7528\u4ecd\u7b49\u9884\u5904\u7406\u7ed3\u679c&#xff0c;\u540e\u9762\u5df2\u7ecf\u5177\u5907\u8f93\u5165\u7684\u8c03\u7528\u4e5f\u53ef\u80fd\u88ab\u5b83\u6321\u4f4f\u3002\u4e0d\u540c Actor \u53ef\u4ee5\u5206\u522b\u6267\u884c&#xff0c;Async \u6216\u7ebf\u7a0b Actor \u5219\u6709\u4e0d\u540c\u7684\u5e76\u53d1\u7ea6\u675f\u3002\u6267\u884c\u987a\u5e8f\u6587\u6863\u8fd8\u7279\u522b\u9650\u5b9a&#xff1a;\u4e0d\u540c\u63d0\u4ea4\u8005\u4e4b\u95f4\u4e0d\u4fdd\u8bc1\u4e0a\u8ff0\u987a\u5e8f&#xff0c;\u5141\u8bb8\u4e71\u5e8f\u914d\u7f6e\u6216\u53d1\u751f\u91cd\u8bd5\u65f6\u4e5f\u4e0d\u80fd\u6cbf\u7528\u9ed8\u8ba4\u987a\u5e8f\u63a8\u65ad\u3002<\/p>\n<p>\u8fdb\u7a0b\u9a7b\u7559\u540c\u6837\u4e0d\u7b49\u4e8e\u4e1a\u52a1\u72b6\u6001\u6301\u4e45\u5316\u3002Actor \u610f\u5916\u9000\u51fa\u540e&#xff0c;\u9ed8\u8ba4\u4e0d\u4f1a\u81ea\u52a8\u91cd\u542f&#xff1b;\u914d\u7f6e max_restarts \u540e&#xff0c;\u91cd\u542f\u4f1a\u91cd\u65b0\u6267\u884c\u6784\u9020\u51fd\u6570\u3002\u8fd9\u4e2a\u8ba1\u6570\u5668\u56e0\u6b64\u4ece\u96f6\u5f00\u59cb&#xff0c;\u800c\u4e0d\u662f\u7ee7\u7eed\u4e0a\u4e00\u6b21\u7684\u503c\u3002\u4e1a\u52a1\u9700\u8981\u6062\u590d\u65f6&#xff0c;\u5fc5\u987b\u81ea\u884c\u6301\u4e45\u5316\u5e76\u5728\u6784\u9020\u6216\u6062\u590d\u903b\u8f91\u4e2d\u8bfb\u53d6\u3002<\/p>\n<p>Actor \u5bb9\u9519\u6587\u6863\u8fd8\u6307\u51fa&#xff0c;\u8c03\u7528\u5df2\u7ecf\u6267\u884c\u4f46 Actor \u5728\u8fd4\u56de\u540e\u7acb\u5373\u6b7b\u4ea1&#xff0c;\u8c03\u7528\u65b9\u4ecd\u53ef\u80fd\u6536\u5230\u9519\u8bef&#xff1b;\u5f00\u542f\u65b9\u6cd5\u91cd\u8bd5\u53c8\u53ef\u80fd\u5e26\u6765\u91cd\u590d\u6267\u884c\u3002\u82e5\u8bc4\u5206\u4e4b\u5916\u8fd8\u8981\u6263\u8d39\u6216\u5199\u4e1a\u52a1\u7ed3\u679c&#xff0c;\u4e0d\u80fd\u9760\u8ba1\u6570\u5668\u5224\u65ad\u201c\u6070\u597d\u6267\u884c\u4e00\u6b21\u201d\u3002\u5e94\u56f4\u7ed5\u8bf7\u6c42\u8eab\u4efd&#xff0c;\u5728\u5916\u90e8\u6301\u4e45\u5316\u7cfb\u7edf\u4e2d\u8bbe\u8ba1\u53bb\u91cd\u4e0e\u5199\u5165\u8bed\u4e49\u3002\u8fd9\u662f\u5e94\u7528\u8981\u8865\u7684\u80fd\u529b&#xff0c;\u4e0b\u9762\u7684\u5c0f\u7a0b\u5e8f\u6ca1\u6709\u5b9e\u73b0\u5b83\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260924044932-6ab4abdccfc40.png\" alt=\"\u56fe04\" \/> <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260924044934-6ab4abde1976a.png\" alt=\"\u56fe05\" \/><\/p>\n<h3>\u628a\u4e00\u6761\u4f9d\u8d56\u94fe\u5199\u6210\u6709\u754c\u6d41\u7a0b<\/h3>\n<p>\u628a\u6240\u6709 get \u90fd\u79fb\u5230\u6700\u540e&#xff0c;\u4e5f\u4e0d\u80fd\u65e0\u9650\u63d0\u4ea4\u3002\u8f93\u5165\u6301\u7eed\u5230\u6765\u800c\u4e0b\u6e38\u6d88\u8d39\u8f83\u6162\u65f6&#xff0c;\u5728\u9014\u5de5\u4f5c\u4f1a\u79ef\u7d2f\u3002Ray \u7684\u9650\u5236 pending tasks \u6a21\u5f0f\u4f7f\u7528 ray.wait \u8ba9\u63d0\u4ea4\u65b9\u9002\u65f6\u505c\u4e0b\u6765&#xff0c;\u5148\u5904\u7406\u5df2\u5c31\u7eea\u7ed3\u679c&#xff0c;\u518d\u91ca\u653e\u63d0\u4ea4\u7a97\u53e3\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u5b8c\u6574\u7684\u5355\u673a\u6559\u5b66\u4ee3\u7801&#xff0c;\u9700\u81ea\u884c\u51c6\u5907 Ray \u73af\u5883\u3002\u4e24\u4efd\u903b\u8f91 CPU \u7684\u5b89\u6392\u7ed9\u4e00\u4e2a Actor \u548c\u9884\u5904\u7406 Task \u7559\u51fa\u8d44\u6e90&#xff1b;\u7a97\u53e3\u8bbe\u4e3a\u4e8c\u53ea\u4e3a\u89c2\u5bdf\u6709\u754c\u884c\u4e3a&#xff0c;\u4e0d\u662f\u6027\u80fd\u63a8\u8350\u503c\u3002\u4e0d\u540c\u8f93\u5165\u7684\u9884\u5904\u7406\u4e0e\u8bc4\u5206\u53ef\u4ee5\u91cd\u53e0&#xff0c;\u8bc4\u5206\u59cb\u7ec8\u4ea4\u7ed9\u540c\u4e00\u4e2a\u540c\u6b65 Actor&#xff0c;\u4ee5\u4fbf\u770b\u6e05\u72b6\u6001\u7684\u8fde\u7eed\u53d8\u5316\u3002<\/p>\n<p><span class=\"token keyword\">import<\/span> ray<\/p>\n<p><span class=\"token decorator annotation punctuation\">&#064;ray<span class=\"token punctuation\">.<\/span>remote<\/span><span class=\"token punctuation\">(<\/span>num_cpus<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">prepare<\/span><span class=\"token punctuation\">(<\/span>request_id<span class=\"token punctuation\">,<\/span> text<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> request_id<span class=\"token punctuation\">,<\/span> text<span class=\"token punctuation\">.<\/span>strip<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>lower<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token decorator annotation punctuation\">&#064;ray<span class=\"token punctuation\">.<\/span>remote<\/span><span class=\"token punctuation\">(<\/span>num_cpus<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Scorer<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>processed <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">score<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> item<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        request_id<span class=\"token punctuation\">,<\/span> text <span class=\"token operator\">&#061;<\/span> item<br \/>\n        self<span class=\"token punctuation\">.<\/span>processed <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token number\">1<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> request_id<span class=\"token punctuation\">,<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>text<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> self<span class=\"token punctuation\">.<\/span>processed<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    ray<span class=\"token punctuation\">.<\/span>init<span class=\"token punctuation\">(<\/span>num_cpus<span class=\"token operator\">&#061;<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        scorer <span class=\"token operator\">&#061;<\/span> Scorer<span class=\"token punctuation\">.<\/span>remote<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        inputs <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;a&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;  Hello &#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;b&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;RAY&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;c&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034; Actor &#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">]<\/span><br \/>\n        pending<span class=\"token punctuation\">,<\/span> results <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><br \/>\n        window <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2<\/span><\/p>\n<p>        <span class=\"token keyword\">def<\/span> <span class=\"token function\">collect_one<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">nonlocal<\/span> pending<br \/>\n            ready<span class=\"token punctuation\">,<\/span> pending <span class=\"token operator\">&#061;<\/span> ray<span class=\"token punctuation\">.<\/span>wait<span class=\"token punctuation\">(<\/span>pending<span class=\"token punctuation\">,<\/span> num_returns<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            request_id<span class=\"token punctuation\">,<\/span> score<span class=\"token punctuation\">,<\/span> processed <span class=\"token operator\">&#061;<\/span> ray<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span>ready<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            results<span class=\"token punctuation\">[<\/span>request_id<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span>score<span class=\"token punctuation\">,<\/span> processed<span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token keyword\">for<\/span> request_id<span class=\"token punctuation\">,<\/span> text <span class=\"token keyword\">in<\/span> inputs<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>pending<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;&#061;<\/span> window<span class=\"token punctuation\">:<\/span><br \/>\n                collect_one<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            prepared_ref <span class=\"token operator\">&#061;<\/span> prepare<span class=\"token punctuation\">.<\/span>remote<span class=\"token punctuation\">(<\/span>request_id<span class=\"token punctuation\">,<\/span> text<span class=\"token punctuation\">)<\/span><br \/>\n            pending<span class=\"token punctuation\">.<\/span>append<span class=\"token punctuation\">(<\/span>scorer<span class=\"token punctuation\">.<\/span>score<span class=\"token punctuation\">.<\/span>remote<span class=\"token punctuation\">(<\/span>prepared_ref<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token keyword\">while<\/span> pending<span class=\"token punctuation\">:<\/span><br \/>\n            collect_one<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token keyword\">assert<\/span> results <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;a&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;b&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;c&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>results<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">finally<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        ray<span class=\"token punctuation\">.<\/span>shutdown<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">if<\/span> __name__ <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#034;__main__&#034;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    main<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd9\u91cc\u4fdd\u7559\u4e86\u4e00\u4e2a\u660e\u786e\u7684\u7b49\u5f85\u70b9&#xff1a;\u7a97\u53e3\u6ee1\u65f6&#xff0c;Driver \u6536\u53d6\u4e00\u4e2a\u7ec8\u7aef\u8bc4\u5206\u7ed3\u679c&#xff0c;\u518d\u7ee7\u7eed\u63d0\u4ea4\u3002\u6bcf\u4e2a\u7ec8\u7aef\u5f15\u7528\u5bf9\u5e94\u4e00\u6761\u201c\u9884\u5904\u7406\u2192\u8bc4\u5206\u201d\u94fe&#xff0c;\u56e0\u6b64\u8be5\u5faa\u73af\u6700\u591a\u4fdd\u7559\u4e24\u6761\u5c1a\u672a\u6536\u53d6\u7ed3\u679c\u7684\u94fe\u3002\u94fe\u4e2d\u540c\u65f6\u5b58\u5728 Task \u548c Actor \u65b9\u6cd5&#xff0c;\u4e0d\u80fd\u628a\u7a97\u53e3\u4e8c\u89e3\u91ca\u6210\u5168\u7cfb\u7edf\u53ea\u6709\u4e24\u4e2a Task&#xff0c;\u66f4\u4e0d\u80fd\u628a\u5b83\u5f53\u6210\u663e\u5b58\u5b57\u8282\u4e0a\u9650\u3002<\/p>\n<p>ray.wait \u8fd4\u56de\u5c31\u7eea\u5f15\u7528&#xff0c;\u4e0d\u4f1a\u628a\u540c\u4e00\u4e2a\u540c\u6b65 Actor \u7684\u65b9\u6cd5\u6539\u6210\u5e76\u884c&#xff0c;\u4e5f\u4e0d\u4f1a\u66ff\u524d\u4e00\u4e2a\u65b9\u6cd5\u89e3\u9664\u8f93\u5165\u4f9d\u8d56\u3002\u672c\u4f8b\u4fdd\u7559\u540c\u4e00\u63d0\u4ea4\u8005\u548c\u9ed8\u8ba4\u6267\u884c\u987a\u5e8f&#xff0c;\u56e0\u6b64\u8ba1\u6570\u65ad\u8a00\u6709\u660e\u786e\u9002\u7528\u6761\u4ef6&#xff1b;\u82e5\u6539\u6210\u591a\u4e2a Actor \u6216\u5e76\u53d1\u65b9\u6cd5&#xff0c;\u5c31\u9700\u8981\u91cd\u65b0\u5b9a\u4e49\u72b6\u6001\u4e0e\u987a\u5e8f\u3002<\/p>\n<p>\u7a97\u53e3\u63a7\u5236\u7684\u662f\u5728\u9014\u5de5\u4f5c\u6570\u91cf\u3002\u771f\u6b63\u80fd\u540c\u65f6\u8fd0\u884c\u591a\u5c11\u4efb\u52a1\u8fd8\u7531\u8d44\u6e90\u51b3\u5b9a&#xff0c;\u7ed3\u679c\u672c\u8eab\u592a\u5927\u4e5f\u53ef\u80fd\u6491\u6ee1\u5185\u5b58\u3002\u672c\u4f8b\u628a\u5c11\u91cf\u7ed3\u679c\u5b58\u5728\u5b57\u5178\u4e2d\u53ea\u662f\u4e3a\u4e86\u65ad\u8a00&#xff1b;\u6301\u7eed\u6d41\u5f0f\u751f\u4ea7\u9700\u8981\u8fb9\u6536\u8fb9\u4ea4\u7ed9\u6d88\u8d39\u8005&#xff0c;\u5e76\u9650\u5236\u7ed3\u679c\u7f13\u51b2&#xff0c;\u800c\u4e0d\u80fd\u6c38\u4e45\u79ef\u7d2f\u8fd9\u4e2a\u5b57\u5178\u3002<\/p>\n<p>\u9047\u5230\u6267\u884c\u6548\u7387\u95ee\u9898\u65f6&#xff0c;\u53ef\u4ee5\u6cbf\u8fd9\u6bb5\u4ee3\u7801\u8fd8\u539f\u4e00\u6b21\u6d41\u7a0b&#xff1a;\u4e0b\u4e00\u4efd\u8c03\u7528\u662f\u5426\u5df2\u63d0\u4ea4&#xff0c;\u4e2d\u95f4\u503c\u662f\u5426\u5fc5\u987b\u56de\u5230 Driver&#xff0c;\u4e0b\u6e38\u5f97\u5230\u7684\u662f\u503c\u8fd8\u662f\u5f15\u7528&#xff0c;\u65b9\u6cd5\u662f\u5426\u843d\u5230\u540c\u4e00\u4e2a Actor&#xff0c;\u63d0\u4ea4\u662f\u5426\u5feb\u4e8e\u6d88\u8d39\u3002\u6bcf\u4e2a\u95ee\u9898\u90fd\u5bf9\u5e94\u4e00\u5904\u53ef\u67e5\u770b\u7684\u4ee3\u7801\u6216\u8fd0\u884c\u8bb0\u5f55\u3002\u5148\u627e\u5230\u5b9e\u9645\u963b\u585e&#xff0c;\u518d\u51b3\u5b9a\u8be5\u6539\u7b49\u5f85\u70b9\u3001\u4f9d\u8d56\u8868\u8fbe\u8fd8\u662f\u5b9e\u4f8b\u7ec4\u7ec7&#xff0c;\u624d\u4e0d\u4f1a\u628a .remote() \u5f53\u6210\u81ea\u52a8\u5e76\u884c\u7684\u5f00\u5173\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260924044935-6ab4abdf5dc3d.png\" alt=\"\u56fe06\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ray \u7684 remote \u8c03\u7528\u4e4b\u540e&#xff1a;\u4efb\u52a1\u600e\u6837\u8854\u63a5&#xff0c;\u72b6\u6001\u7559\u5728\u54ea\u91cc<br \/>\n\u628a\u4e00\u6279\u6587\u672c\u7684\u9884\u5904\u7406\u51fd\u6570\u52a0\u4e0a ray.remote&#xff0c;\u518d\u9010\u6761\u8c03\u7528&#xff0c;\u7a0b\u5e8f\u770b\u8d77\u6765\u5df2\u7ecf\u201c\u5206\u5e03\u5f0f\u5316\u201d\u3002\u4f46\u4e0b\u9762\u8fd9\u4e2a\u5faa\u73af\u4ecd\u7136\u662f\u4e00\u4efd\u5de5\u4f5c\u7ed3\u675f&#xff0c;\u624d\u63d0\u4ea4\u4e0b\u4e00\u4efd&#xff1a;<br \/>\nfor text in texts:value  ray.get(prepare.remote(text))consume(value)\u5373\u4f7f\u53e6\u4e00\u4e2a Worker \u7a7a\u95f2&#xff0c;\u5b83\u4e5f\u65e0<\/p>\n","protected":false},"author":2,"featured_media":109551,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10848,11653,66,3264,5058,50],"topic":[],"class_list":["post-109557","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-harness","tag-11653","tag-ai","tag-claude","tag-codex","tag-50"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Ray \u7684 remote \u8c03\u7528\u4e4b\u540e\uff1a\u4efb\u52a1\u600e\u6837\u8854\u63a5\uff0c\u72b6\u6001\u7559\u5728\u54ea\u91cc? - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/109557.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ray \u7684 remote \u8c03\u7528\u4e4b\u540e\uff1a\u4efb\u52a1\u600e\u6837\u8854\u63a5\uff0c\u72b6\u6001\u7559\u5728\u54ea\u91cc? - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Ray \u7684 remote \u8c03\u7528\u4e4b\u540e&#xff1a;\u4efb\u52a1\u600e\u6837\u8854\u63a5&#xff0c;\u72b6\u6001\u7559\u5728\u54ea\u91cc \u628a\u4e00\u6279\u6587\u672c\u7684\u9884\u5904\u7406\u51fd\u6570\u52a0\u4e0a ray.remote&#xff0c;\u518d\u9010\u6761\u8c03\u7528&#xff0c;\u7a0b\u5e8f\u770b\u8d77\u6765\u5df2\u7ecf\u201c\u5206\u5e03\u5f0f\u5316\u201d\u3002\u4f46\u4e0b\u9762\u8fd9\u4e2a\u5faa\u73af\u4ecd\u7136\u662f\u4e00\u4efd\u5de5\u4f5c\u7ed3\u675f&#xff0c;\u624d\u63d0\u4ea4\u4e0b\u4e00\u4efd&#xff1a; for text in texts:value ray.get(prepare.remote(text))consume(value)\u5373\u4f7f\u53e6\u4e00\u4e2a Worker \u7a7a\u95f2&#xff0c;\u5b83\u4e5f\u65e0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/109557.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-24T04:49:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260924044927-6ab4abd7f00c4.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/109557.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/109557.html\",\"name\":\"Ray \u7684 remote \u8c03\u7528\u4e4b\u540e\uff1a\u4efb\u52a1\u600e\u6837\u8854\u63a5\uff0c\u72b6\u6001\u7559\u5728\u54ea\u91cc? - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-24T04:49:38+00:00\",\"dateModified\":\"2026-09-24T04:49:38+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/109557.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/109557.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/109557.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ray \u7684 remote \u8c03\u7528\u4e4b\u540e\uff1a\u4efb\u52a1\u600e\u6837\u8854\u63a5\uff0c\u72b6\u6001\u7559\u5728\u54ea\u91cc?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ray \u7684 remote \u8c03\u7528\u4e4b\u540e\uff1a\u4efb\u52a1\u600e\u6837\u8854\u63a5\uff0c\u72b6\u6001\u7559\u5728\u54ea\u91cc? - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/109557.html","og_locale":"zh_CN","og_type":"article","og_title":"Ray \u7684 remote \u8c03\u7528\u4e4b\u540e\uff1a\u4efb\u52a1\u600e\u6837\u8854\u63a5\uff0c\u72b6\u6001\u7559\u5728\u54ea\u91cc? - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Ray \u7684 remote \u8c03\u7528\u4e4b\u540e&#xff1a;\u4efb\u52a1\u600e\u6837\u8854\u63a5&#xff0c;\u72b6\u6001\u7559\u5728\u54ea\u91cc \u628a\u4e00\u6279\u6587\u672c\u7684\u9884\u5904\u7406\u51fd\u6570\u52a0\u4e0a ray.remote&#xff0c;\u518d\u9010\u6761\u8c03\u7528&#xff0c;\u7a0b\u5e8f\u770b\u8d77\u6765\u5df2\u7ecf\u201c\u5206\u5e03\u5f0f\u5316\u201d\u3002\u4f46\u4e0b\u9762\u8fd9\u4e2a\u5faa\u73af\u4ecd\u7136\u662f\u4e00\u4efd\u5de5\u4f5c\u7ed3\u675f&#xff0c;\u624d\u63d0\u4ea4\u4e0b\u4e00\u4efd&#xff1a; for text in texts:value ray.get(prepare.remote(text))consume(value)\u5373\u4f7f\u53e6\u4e00\u4e2a Worker \u7a7a\u95f2&#xff0c;\u5b83\u4e5f\u65e0","og_url":"https:\/\/www.wsisp.com\/helps\/109557.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-24T04:49:38+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260924044927-6ab4abd7f00c4.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/109557.html","url":"https:\/\/www.wsisp.com\/helps\/109557.html","name":"Ray \u7684 remote \u8c03\u7528\u4e4b\u540e\uff1a\u4efb\u52a1\u600e\u6837\u8854\u63a5\uff0c\u72b6\u6001\u7559\u5728\u54ea\u91cc? - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-24T04:49:38+00:00","dateModified":"2026-09-24T04:49:38+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/109557.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/109557.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/109557.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Ray \u7684 remote \u8c03\u7528\u4e4b\u540e\uff1a\u4efb\u52a1\u600e\u6837\u8854\u63a5\uff0c\u72b6\u6001\u7559\u5728\u54ea\u91cc?"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/109557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=109557"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/109557\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/109551"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=109557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=109557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=109557"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=109557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}