{"id":217094,"date":"2020-11-28T05:39:38","date_gmt":"2020-11-27T21:39:38","guid":{"rendered":"http:\/\/4563.org\/?p=217094"},"modified":"2020-11-28T05:39:38","modified_gmt":"2020-11-27T21:39:38","slug":"python-%e5%a4%9a%e8%bf%9b%e7%a8%8b%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=217094","title":{"rendered":"Python \u591a\u8fdb\u7a0b\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python \u591a\u8fdb\u7a0b\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : frmongo <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5728\u4e00\u4e2a linux \u4e3b\u673a\u4e0a\uff0c\u6211\u60f3\u540c\u65f6\u5f00\u59cb\u64ad\u653e\u97f3\u4e50\u548c\u5f55\u97f3\uff08\u6709\u9ea6\u514b\u98ce\uff09\uff0c\u671f\u671b\u5f55\u97f3\u7ed3\u675f\uff0c\u97f3\u4e50\u81ea\u52a8\u505c\u6b62\u3002 \u73b0\u5728\u53ea\u9700\u8981\u5f55\u97f3 20 \u79d2\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u5f55\u97f3\u7ed3\u675f\u540e\uff0c\u97f3\u4e50\u4e0d\u4f1a\u505c\u6b62\uff0c\u600e\u4e48\u5199\u53ef\u4ee5\u5b9e\u73b0\u76ee\u7684\u5462<\/p>\n<pre><code># coding:utf-8  from multiprocessing import Process as process import os  def play_music():     cmd1 = \"aplay muisc.wav\"     os.system(cmd1)  def record():     cmd1 = \"arecord -r 16000 -t wav -d 20 -v out.wav\"     os.system(cmd1)  if __name__ == '__main__':          p1 = process(target=play_music)     p1.daemon=True     p1.start()     record()     p1.terminate()     p1.join() <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>9<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4409014\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ruanimal <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u76f4\u63a5\u7528 subprocess.popen \u5c31\u597d\u4e86\u554a\uff0c\u7528\u5565 multiprocessing \u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4409015\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jkhere <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u662f\u5f88\u597d\u5b9e\u73b0\uff0c\u5b50\u8fdb\u7a0b\u5f00\u59cb\u6267\u884c\u540e\uff0c\u4e3b\u8fdb\u7a0b\u5c31\u65e0\u6cd5\u7cbe\u786e\u63a7\u5236\u5b50\u8fdb\u7a0b\u4e86\u3002<br \/>\u5047\u8bbe\u4f60\u5b50\u8fdb\u7a0b\u5f00\u59cb\u540e\uff0c\u4e3b\u8fdb\u7a0b\u5f00\u59cb\u8ba1\u65f6\uff0c\u5230\u65f6\u95f4\u540e\u6740\u6b7b\u5b50\u8fdb\u7a0b\uff0c\u8fd9\u6837\u4e5f\u53ea\u662f\u7c97\u7565\u7684\u63a7\u5236\u65f6\u95f4\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4409016\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mingl0280 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5148\u5f00\u59cb\u653e\u97f3\u4e50\uff0c\u518d\u542f\u52a8\u5f55\u97f3\uff0c\u5f55\u97f3\u8fd4\u56de\u4ee5\u540e\uff08 system \u6709\u8fd4\u56de\u503c\u5427\uff09 kill \u6389\u653e\u97f3\u2026\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4409017\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ruanimal \u6211\u4e5f\u89c9\u5f97\u5e94\u8be5\u76f4\u63a5\u4f7f\u7528 subprocess.popen \u3002play_music \u5c31\u53ea\u662f\u8c03\u7528 shell \u542f\u52a8\u4e2a\u65b0\u8fdb\u7a0b\uff0c\u4e0d\u5982\u76f4\u63a5\u81ea\u5df1\u542f\u52a8\u65b0\u8fdb\u7a0b\uff0c\u6ca1\u5fc5\u8981\u7ed5\u4e00\u5708\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4409018\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ruanimal <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ysc3839 \u610f\u601d\u662f\u7528 subprocess.popen \u66ff\u6362 multiprocessing \u548c os.system                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4409019\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ruanimal \u662f\u7684\uff0c\u6211\u5c31\u662f\u60f3\u8868\u8fbe\u8fd9\u4e2a\u610f\u601d\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4409020\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : NeezerGu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/www.notion.so\/image\/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F6cca620b-71c7-4204-8b3f-ba6fa526c8ca%2FUntitled.png?table=block&amp;id=1a34c76c-7b1e-4c22-ba85-199194a1edf6&amp;width=3840&amp;userId=&amp;cache=v2<\/p>\n<p>https:\/\/www.notion.so\/neezer\/python-a216d49fb46040e181ae70df69d247f2<\/p>\n<p>\u5f88\u4e45\u6ca1\u5199\u591a\u8fdb\u7a0b\u4e86\uff0c\u4e0d\u77e5\u9053\u8fd9\u6837\u53ef\u4ee5\u5417\uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4409021\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jkhere <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7ed9\u4f60\u4e2a demo\uff0c\u7528 python \u7684\u534f\u7a0b\u5427\uff1a<\/p>\n<p>import asyncio<\/p>\n<p>async def eternity():<br \/> # do your job<br \/> while True:<br \/> print(&#8216;doing!&#8217;)<\/p>\n<p>async def main():<br \/> # Wait for at most 20 second<br \/> try:<br \/> await asyncio.wait_for(eternity(), timeout=20.0)<br \/> except asyncio.TimeoutError:<br \/> print(&#8216;timeout! job done&#8217;)<\/p>\n<p>asyncio.run(main())                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4409022\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jkhere <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8220;`python<br \/>import asyncio<\/p>\n<p>async def eternity():<br \/># do your job<br \/> while True:<br \/> print(&#8216;doing!&#8217;)<\/p>\n<p>async def main():<br \/># Wait for at most 20 second<br \/>try:<br \/> await asyncio.wait_for(eternity(), timeout=20.0)<br \/>except asyncio.TimeoutError:<br \/> print(&#8216;timeout! job done&#8217;)<\/p>\n<p>asyncio.run(main())<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python \u591a\u8fdb\u7a0b\u95ee\u9898 \u8cc7\u6df1\u5927\u4f6c&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/217094"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=217094"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/217094\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=217094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=217094"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=217094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}