{"id":85865,"date":"2020-05-13T15:30:16","date_gmt":"2020-05-13T07:30:16","guid":{"rendered":"http:\/\/4563.org\/?p=85865"},"modified":"2020-05-13T15:30:16","modified_gmt":"2020-05-13T07:30:16","slug":"%e6%b1%82%e5%8a%a9%ef%bc%9a-pyqt5-%e7%9a%84%e4%b8%80%e4%b8%aa%e7%ba%bf%e7%a8%8b%e5%8d%a0%e7%94%a8-cpu-%e5%af%bc%e8%87%b4%e5%8f%a6%e4%b8%80%e4%b8%aa%e7%ba%bf%e7%a8%8b%e5%93%8d%e5%ba%94%e5%8f%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=85865","title":{"rendered":"\u6c42\u52a9\uff1a PyQt5 \u7684\u4e00\u4e2a\u7ebf\u7a0b\u5360\u7528 CPU \u5bfc\u81f4\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u54cd\u5e94\u53d8\u6162"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6c42\u52a9\uff1a PyQt5 \u7684\u4e00\u4e2a\u7ebf\u7a0b\u5360\u7528 CPU \u5bfc\u81f4\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u54cd\u5e94\u53d8\u6162               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wangyz1997 <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6211\u4e4b\u524d\u662f\u641e\u5d4c\u5165\u5f0f\u7684\uff0c\u73b0\u5728\u8981\u5199\u4e00\u4e2a\u4e0a\u4f4d\u673a\uff0c\u9009\u62e9\u4f7f\u7528 Python+PyQt5 \u6765\u5b8c\u6210\u3002\u6211\u7684\u7a0b\u5e8f\u6709\u4e24\u4e2a\u6267\u884c\u7ebf\u7a0b\u4ee5\u53ca\u4e00\u4e2a\u4e3b\u7ebf\u7a0b\uff0c\u4e3b\u7ebf\u7a0b\u521d\u59cb\u5316\u5b8c\u4e24\u4e2a\u6267\u884c\u7ebf\u7a0b\u4e4b\u540e\uff0c\u4e00\u4e2a\u6267\u884c\u7ebf\u7a0b\u8fdb\u884c\u4e32\u53e3\u7684\u6570\u636e\u4ea4\u4e92\uff0c\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u6267\u884c\u4e00\u4e2a\u6bd4\u8f83\u8017\u65f6\u7684\u64cd\u4f5c\uff08 OpenCV \u56fe\u50cf\u5904\u7406\uff09\uff0c\u5b8c\u5168\u5360\u6ee1 CPU \u3002 \u8fd9\u4e24\u4e2a\u7ebf\u7a0b\u90fd\u662f\u4f7f\u7528 QThread \u6765\u5b8c\u6210\u7684\uff0c\u73b0\u5728\u9047\u5230\u4e86\u4e00\u4e2a\u95ee\u9898\uff1a\u56fe\u50cf\u5904\u7406\u7ebf\u7a0b\u957f\u65f6\u95f4\u7684\u8ba1\u7b97\uff0c\u4f1a\u5bfc\u81f4\u4e32\u53e3\u7ebf\u7a0b\u51fa\u73b0\u54cd\u5e94\u53d8\u6162\u7684\u73b0\u8c61\uff08\u4e32\u53e3\u4e22\u5305\u5bfc\u81f4\u901a\u4fe1\u5931\u8d25\uff09\uff0c\u4e0e\u6b64\u540c\u65f6\u4e3b\u7ebf\u7a0b\u7684 UI \u64cd\u4f5c\u4e5f\u4f1a\u5361\u987f\u3002 \u4e0b\u9762\u662f\u90e8\u5206\u4ee3\u7801\u3002<\/p>\n<pre><code>class MainWindowClass(QMainWindow, Ui_MainWindow):  def __init__(self):   super(MainWindowClass, self).__init__()  # \u521d\u59cb\u5316\u7236\u7c7b   self.setupUi(self)  # \u521d\u59cb\u5316\u7a97\u53e3    self.imgProcTrd = ThreadImageProc(op_param, op_cam_idx)  # \u521b\u5efa\u56fe\u50cf\u5904\u7406\u7ebf\u7a0b   self.imgProcTrd.signalImageSend.connect(self.callback_image_display)  # \u8fde\u63a5\u56de\u4f20\u5230 GUI \u7684\u4e8b\u4ef6    self.serialCommTrd = ThreadSerialComm()  # \u521b\u5efa\u4e32\u53e3\u901a\u4fe1\u7ebf\u7a0b   self.serialCommTrd.signalSerialStatus.connect(self.callback_serial_event)   class ThreadImageProc(QThread):  #  \u901a\u8fc7\u7c7b\u6210\u5458\u5bf9\u8c61\u5b9a\u4e49\u4fe1\u53f7\u5bf9\u8c61  signalImageSend = pyqtSignal(numpy.ndarray)   def __init__(self, op_param, cam_idx):   super(ThreadImageProc, self).__init__()   def run(self):   while True:    ret, cap_img = cap.read()    img = self.image_proc(cap_img)    self.signalImageSend.emit(img)   class ThreadSerialComm(QThread):  signalSerialStatus = pyqtSignal(list)  # \u4e32\u53e3\u4e0a\u62a5    def __init__(self):   super(ThreadSerialComm, self).__init__()   def run(self):    while True:   # \u7701\u7565\u4e32\u53e3\u901a\u4fe1\u51fd\u6570 <\/code><\/pre>\n<p>\u60f3\u8bf7\u95ee\u4e00\u4e0b\u5404\u4f4d\u5927\u4f6c\u8fd9\u662f\u4ec0\u4e48\u60c5\u51b5\uff1f\u6709\u6ca1\u6709\u89e3\u51b3\u65b9\u6848\uff1f RTOS \u662f\u62a2\u5360\u5f0f\u7cfb\u7edf\uff0c\u5373\u4f7f\u662f\u5355\u6838\u5fc3\u7684\u5d4c\u5165\u5f0f\u5904\u7406\u5668\u4e5f\u4f1a\u4fdd\u8bc1\u6bcf\u8fc7\u4e00\u4e2a Tick \u6267\u884c\u4e00\u6b21\u4efb\u52a1\u8c03\u5ea6\u6765\u786e\u4fdd\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u5f97\u4ee5\u62a2\u5360 CPU \u3002\u6309\u7167\u6211\u7684\u7406\u89e3\uff0c\u7535\u8111\u8fd9\u79cd\u591a\u6838\u5fc3\u5904\u7406\u5668\u5e94\u8be5\u662f\u628a\u591a\u4e2a\u7ebf\u7a0b\u5206\u914d\u7ed9\u591a\u4e2a\u6838\u5fc3\u6267\u884c\u7684\uff08\u4ec5\u4ec5\u662f\u6211\u5f88\u521d\u7ea7\u7684\u7406\u89e3\uff0c\u671b\u8d50\u6559\uff09\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u8fd9\u79cd\u5b50\u7ebf\u7a0b\u5361\u6b7b\u5176\u4ed6\u7ebf\u7a0b\u751a\u81f3 UI \u7ebf\u7a0b\u7684\u5462\uff1f\u6709\u6ca1\u6709\u4ec0\u4e48\u89e3\u51b3\u65b9\u6cd5\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>29<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1499185\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : gainsurier <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528\u4e00\u4e9b perf \u6216\u8005 monitor \u8f6f\u4ef6\u770b\u4e00\u4e0b cpu \u5360\u7528\u7684\u70ed\u70b9\u51fd\u6570\uff0c\u7136\u540e\u9488\u5bf9\u4f18\u5316                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499186\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhuangzhuang1988 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u53ef\u4ee5\u7684\u8bdd\u6362 C# + Emgu CV \u8bd5\u8bd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499187\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wangyz1997 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @gainsurier \u6211\u5df2\u7ecf\u77e5\u9053\u662f\u54ea\u4e2a\u51fd\u6570\u5360\u7528\u65f6\u95f4\u4e86\uff08\u56e0\u4e3a\u5220\u6389\u8fd9\u4e2a\u51fd\u6570\u901f\u5ea6\u5c31\u6b63\u5e38\u4e86\uff09\uff0c\u4f46\u662f\u6211\u597d\u5947\u7684\u662f\u4e3a\u4ec0\u4e48\u6211\u660e\u660e\u628a\u8017\u65f6\u7684\u51fd\u6570\u4ece\u4e3b\u7ebf\u7a0b\u91cc\u5206\u79bb\u51fa\u6765\u4e86\uff0c\u8fd8\u662f\u4f1a\u5bfc\u81f4\u4e3b\u7ebf\u7a0b\u751a\u81f3\u5176\u4ed6\u7ebf\u7a0b\u54cd\u5e94\u6162\u3002<\/p>\n<p>@zhuangzhuang1988 \u5df2\u7ecf\u5f00\u53d1\u4e86\u5f88\u591a\u4e86\uff0c\u5e94\u8be5\u662f\u6ca1\u6cd5\u6362\u4e86\u2026\u2026\u800c\u4e14\u6211\u662f\u641e\u5d4c\u5165\u5f0f\u7684\u534a\u8def\u51fa\u5bb6\u7684\uff0c\u8ba9\u6211\u5728\u5b66\u4e00\u95e8\u8bed\u8a00\u96be\u5ea6\u8fd8\u662f\u504f\u9ad8\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499188\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jin7 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             python \u7684\u591a\u7ebf\u7a0b\u597d\u50cf\u662f\u5047\u7684?<br \/>\u80af\u5b9a\u6709\u529e\u6cd5\u89e3\u51b3 \u4e0d\u7136\u522b\u4eba\u600e\u4e48\u80fd\u884c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499189\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : weyou <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             CPU \u5bc6\u96c6\u578b\u64cd\u4f5c\u7ebf\u7a0b\u53d7\u5230 GIL \u7684\u9650\u5236\u6bd4\u8f83\u5927\uff0c\u51e0\u4e4e\u76f8\u5f53\u4e8e\u5355\u7ebf\u7a0b\u3002\u53ef\u4ee5\u4f7f\u7528 multiprocessing \u907f\u514d\u8fd9\u4e2a\u95ee\u9898                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499190\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aa6563679 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528\u591a\u8fdb\u7a0b\u5427\uff0c\u987a\u4fbf\u628a\u5b50\u8fdb\u7a0b CPU \u4f18\u5148\u7ea7\u964d\u4f4e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499191\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wangyz1997 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @weyou <br \/>@aa6563679 <br \/>\u611f\u8c22\uff0c\u6211\u53bb\u8bd5\u4e00\u8bd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499192\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wangyz1997 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @weyou \u5982\u679c\u6211\u8c03\u7528\u7684\u662f C \u8bed\u8a00\u5c01\u88c5\u597d\u7684\u5e93\uff0c\u8fd8\u53d7\u89e3\u91ca\u5668\u9501\u7684\u9650\u5236\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499193\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : weyou <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wangyz1997 \u8fd9\u662f\u7531\u8fd9\u4e2a\u5e93\u51b3\u5b9a\u7684\u3002\u6bd4\u5982 Qt \u5c31\u4f1a\u5728 C++\u7684 boundary \u5904\u91ca\u653e GIL\uff0c\u4f46\u662f QThread \u7684\u7ebf\u7a0b\u4f53\u662f Python code \u7684\u8bdd\uff0c\u540c\u6837\u4f1a\u53d7\u5230 GIL \u7684\u63a7\u5236\uff0c\u4e0d\u80fd\u4f8b\u5916                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499194\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zk8802 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u8017\u65f6\u7684\u51fd\u6570\u7684\u8fd0\u884c\u65f6\u95f4\u4e0d\u662f\u5f88\u5173\u952e\uff0c\u4f60\u53ef\u4ee5\u5728 while True \u5faa\u73af\u91cc\u9762\u52a0\u4e0a time.sleep(0.0000001) \u4ee5\u5b9a\u671f\u91ca\u653e GIL \u3002\u5177\u4f53\u591a\u5c11\u4e2a\u5faa\u73af\u8c03\u7528\u4e00\u6b21 sleep\uff0c\u9700\u8981\u8c03\u8bd5\u4e00\u4e0b\u3001\u770b\u770b\u5982\u4f55\u624d\u80fd\u4e0d\u5361\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499195\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : inframe <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5efa\u8bae\uff1a<br \/>\u7528 process explorer \u770b\u770b CPU \u5bc6\u96c6\u8fd0\u884c\u65f6\uff0c<br \/>\u5de5\u4f5c\u7ebf\u7a0b\u7684\u72b6\u6001\uff0c\u68c0\u67e5\u4e00\u4e0b\u4ee3\u7801\u662f\u5426\u8fd0\u884c\u5728 Gil \u9650\u5236\u4e2d\uff0c\u53ef\u4ee5 suspend \u4e00\u4e2a\u8fdb\u7a0b\uff0c\u7136\u540e\u6328\u4e2a\u67e5\u770b\u7ebf\u7a0b\u5806\u6808<\/p>\n<p>\u90e8\u5206\u4ee3\u7801\u7528 Cython \u91cd\u5199\u4e00\u4e0b\u7f16\u8bd1\u4e3a pyd \u52a0\u8f7d\uff0c<br \/>\u53ea\u8981\u4e0d\u662f Python native code \u90fd\u4e0d\u4f1a\u9047\u5230 Gil \u9650\u5236\u591a\u6838\u5fc3\uff0c\u5f53\u7136 multi process \u4e5f\u53ef\u4ee5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499196\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Drahcir <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7531\u4e8e GIL\uff0cPython CPU \u5bc6\u96c6\u578b\u4efb\u52a1\u4e0d\u8981\u7528\u591a\u7ebf\u7a0b\uff0c\u7528 multiprocessing \u3002\u81ea\u5df1\u505a\u597d\u8fdb\u7a0b\u95f4\u901a\u4fe1\u5373\u53ef\u3002<br \/>\u867d\u7136\u6709 C-extension \u5e93\uff08\u6bd4\u5982 pyqt \uff09\u53ef\u4ee5\u5728 C \u7a7a\u95f4\u5185\u7a81\u7834 GIL\uff0c\u4f46\u662f\u53ea\u8981\u5b58\u5728 python \/ c \u4ea4\u4e92\uff0c\u5c31\u4ecd\u53d7 GIL \u9650\u5236\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499197\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e24\u4e2a Thread \u90fd\u662f while True\uff0c\u4e5f\u6ca1\u6709\u770b\u5230\u7ed3\u675f\u6761\u4ef6\uff0c\u65e0\u9650\u6267\u884c\uff1f\u5efa\u8bae\u6539\u4e3a\u6709\u6761\u4ef6\u5faa\u73af<\/p>\n<p>ThreadSerialComm \u662f\u8ddf\u968f\u4e3b\u7ebf\u7a0b\u4e0d\u65ad\u6267\u884c\u7684\u4e48\uff1f\u5173\u95ed\u7a97\u53e3\u624d\u7ed3\u675f\uff1f<br \/>\u5982\u679c\u662f\u8fd9\u6837\uff0c\u5efa\u8bae\u6539\u4e3a\u5b9a\u65f6\u89e6\u53d1\uff0cQtCore.QTimer()\uff0cwhile \u7528\u961f\u5217\u5224\u65ad\uff0c\u6709\u901a\u4fe1\u8bf7\u6c42\u6254\u8fdb\u961f\u5217\uff0c\u5224\u65ad\u961f\u5217\u4e0d\u662f empty \u624d\u6267\u884c\u7ebf\u7a0b\uff0cempty \u5c31\u7ed3\u675f\uff0c\u7b49\u5f85\u4e0b\u6b21 timer \u89e6\u53d1<\/p>\n<p>\u5168\u90e8\u90fd\u662f while true \u3001\u53c8\u6ca1\u6709\u7ed3\u675f\u6761\u4ef6\u5e94\u8be5\u662f\u75c7\u7ed3\u6240\u5728                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499198\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wangyz1997 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zk8802 <br \/>@inframe <br \/>@Drahcir <br \/>\u611f\u8c22\uff0c\u770b\u6765\u8981\u5b66\u4e60\u4e00\u4e0b\u591a\u8fdb\u7a0b\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499199\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wangyz1997 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @imn1 \u6211\u5728 ThreadSerialComm \u91cc\u6709\u4e00\u4e2a\u8d85\u65f6 50ms \u7684 IO \u64cd\u4f5c\uff08\u4e32\u53e3\u901a\u4fe1\uff09\uff0c\u662f\u4e0d\u662f\u8fd9\u6837\u5c31\u548c QTimer \u7684\u6548\u679c\u5dee\u4e0d\u591a\u4e86\u5462\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499200\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wangyz1997 #15<br \/>\u6211\u89c9\u5f97\u4e0d\u884c\uff0c\u6211\u8bf4\u4e0d\u6e05\u695a\uff0c\u6211\u4e5f\u4e0d\u719f\u6089\u7ebf\u7a0b<br \/>\u4e0d\u8fc7\u53ef\u4ee5\u8bf4\u8bf4\u6211\u5199\u7684\u4f8b\u5b50<br \/>\u4e00\u4e2a\u6d88\u606f thread\uff0c\u53d1\u9001\u53f3\u4e0b\u89d2\u6d88\u606f\uff0c\u56e0\u4e3a\u4e0d\u8bba\u90a3\u4e2a\u63a7\u4ef6\u53d1\u51fa\uff0c\u90fd\u7531\u8fd9\u4e2a thread \u7ba1\u7406\uff0c\u6240\u4ee5\u8bbe\u540e\u53f0 timer \u5faa\u73af\u6bcf\u4e24\u79d2\u89e6\u53d1<br \/>\u4e00\u4e2a hash thread\uff0c\u591a\u6587\u4ef6 hash\uff0c\u4e5f\u662f\u957f\u65f6\u95f4\uff0c\u6709\u65f6\u957f\u8fbe\u51e0\u5341\u5206\u949f\u751a\u81f3\u4e00\u5c0f\u65f6\uff0c\u7531\u6309\u94ae\u89e6\u53d1\uff0c\u5faa\u73af\u4f7f\u7528 for<br \/>\u5f53\u7136\u8fd8\u6709\u5176\u4ed6\uff08\u5171 10+\u4e2a thread class \uff09\uff0c\u4e0d\u8fc7 hash \u65f6\u5f88\u5403 CPU\uff0c\u4e00\u822c\u4e5f\u4e0d\u4f5c\u5176\u4ed6\u590d\u6742\u64cd\u4f5c\uff0c\u4f46\u95ee\u9898\u4e0d\u5728\u8fd9\u91cc<\/p>\n<p>\u5982\u679c\u6211\u628a timer \u653e\u5230 thread class \u91cc\u9762\uff0c\u5c31\u662f start \u540e\uff0c\u6839\u636e timer 2 \u79d2\u4e00\u6b21\u5faa\u73af\uff0c\u5355\u5355\u8fd9\u6837\uff0c\u4e3b\u7a97\u53e3\u5c31\u5df2\u7ecf\u53cd\u5e94\u8fdf\u7f13\u4e86\uff0c\u6240\u4ee5\u6839\u672c\u4e0d\u662f hash \u7684\u95ee\u9898\uff0c\u56e0\u4e3a\u90fd\u6ca1\u542f\u52a8\u3002\u540e\u6765\u6539\u6210 timer \u653e\u5728\u4e3b\u7ebf\u7a0b\uff0cinit \u65f6\u542f\u52a8 timer\uff0c\u6bcf\u6b21 timeout \u65f6\u89e6\u53d1 thread \u68c0\u67e5\u6d88\u606f\u961f\u5217\uff0c\u8fd9\u6837\u5c31\u6ca1\u95ee\u9898\u4e86<br \/>\u53e6\u5916\uff0c\u5efa\u8bae\u957f\u65f6\u95f4\u7684 thread\uff0c\u5728\u6bcf\u6b21\u5faa\u73af\u90fd emit \u4e00\u6b21\uff08\u6211\u662f emit \u5230\u8fdb\u5ea6\u6761\uff09\uff0c\u8fd9\u6837\u4e5f\u76f8\u5f53\u4e8e\u6253\u4e2a\u201c\u65ad\u70b9\u201d\uff0c\u5bf9 py \u5904\u7406\u7ebf\u7a0b\u6709\u5e2e\u52a9<\/p>\n<p>\u4e0a\u8ff0\u8fd9\u4e9b\u6211\u90fd\u8bf4\u4e0d\u51fa\u4ec0\u4e48\u9053\u7406\uff0c\u53cd\u6b63\u770b\u770b\u522b\u4eba\u7684\u4f8b\u5b50\uff0c\u7136\u540e\u60f3\u60f3\u534f\u7a0b\u7ba1\u7406\u90a3\u79cd\u4e5f\u662f\u8fd9\u6837\u6253\u201c\u65ad\u70b9\u201d\u5207\u6362\uff0c\u81ea\u5df1\u6478\u7d22\u7740\u7406\u987a\u7684                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499201\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jones2000 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7ebf\u7a0b\u91cc\u7528\u4fe1\u53f7\u7b49\u5f85\u6765\u89e6\u53d1\uff0c \u4e0d\u8981 while(true) \u8fd9\u6837\u4f60\u7684\u7ebf\u7a0b\u8fd8\u662f\u518d\u5360\u7528 cpu\uff0c\u9700\u8981\u7528 WaitForSingleObject \u8fd9\u4e9b\u51fd\u6570\uff0c \u624d\u80fd\u91ca\u653e\u5f53\u524d\u7ebf\u7a0b\u4e0d\u4f7f\u7528 cpu\uff0c \u7b49\u5230\u4fe1\u53f7\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499202\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wangyz1997 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @imn1 \u611f\u8c22                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499203\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wangyz1997 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jones2000 \u6211\u7684\u56fe\u50cf\u5904\u7406\u7ebf\u7a0b\u662f\u8bfb\u53d6\u6444\u50cf\u5934\uff0c\u7136\u540e\u8fdb\u884c\u56fe\u50cf\u7b97\u6cd5\u5e76\u5c06\u7ed3\u679c emit \u5230\u4e3b\u7ebf\u7a0b\u4e2d\u3002\u6211\u60f3\u6cd5\u4e2d\u662f\u8ba9\u8fd9\u4e2a\u7ebf\u7a0b\u4ee5\u6700\u9ad8\u7684\u901f\u5ea6\u8fd0\u884c\uff0c\u4e0d\u9700\u8981\u63a5\u53d7\u5916\u90e8\u7684\u4fe1\u53f7\u4e4b\u7c7b\u7684\uff0c\u53ea\u9700\u8981\u5b8c\u6210\u5b83\u81ea\u5df1\u7684\u8bfb\u53d6-\u5904\u7406-\u53d1\u9001\u5c31\u53ef\u4ee5\u4e86\u3002\u8bf7\u95ee\u8fd9\u6837\u8be5\u600e\u4e48\u91ca\u653e CPU \u5462\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499204\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wangyz1997 #19<br \/>\u6211\u6bd4\u8f83\u597d\u5947\u662f\u4f60\u6bcf\u4e00\u5e27\u90fd\u8981\u6355\u6349\u4e48\uff1f\u4e0d\u9700\u8981\u957f\u671f\u8fd0\u884c\u6355\u6349 thread \u7684\u5427<\/p>\n<p>\u6211\u89c9\u5f97\u4f60\u8fd9\u4e2a\u662f\u6709\u987a\u5e8f\u6267\u884c\u7684\uff0c\u6ca1\u5fc5\u8981\u5206\u4e24\u4e2a thread\uff0c\u5199\u5230\u4e00\u4e2a thread \u91cc\u9762\u4e24\u4e2a\u51fd\u6570\u987a\u5e8f\u6267\u884c\u5c31\u597d<br \/>\u5982\u679c\u662f\u591a\u6b21\u6355\u6349\u5e76\u5904\u7406\uff0c\u5e94\u8be5\u5728 thread \u5185\u7528\u591a\u8fdb\u7a0b\u5e76\u884c<\/p>\n<p>\u53e6\u5916\u4e00\u4e2a thread \u4e0d\u5e94\u591a\u6b21\u8fd0\u884c\uff0c\u6240\u4ee5\u6211\u57fa\u672c\u90fd\u6709\u7c7b\u4f3c\u7684\u8bed\u53e5\u5148\u5224\u65ad\u624d\u542f\u52a8<br \/>if not self.hashThread.isRunning():self.hashThread.start()                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499205\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jones2000 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wangyz1997 \u5173\u952e\u70b9\u5728\u4f60\u7684\u8bfb\u53d6\u7684\u8fd9\u4e2a\u5730\u65b9\uff0c \u5982\u679c\u4f60\u7684\u6570\u636e\u662f\u6709\u66f4\u65b0\u9891\u7387\u7684\uff0c\u90a3\u8bfb\u53d6\u4e00\u6b21\u5b8c\u6210\u4ee5\u540e\uff0c \u9700\u8981\u91ca\u653e cpu \uff08\u4f7f\u7528\u4fe1\u53f7\u7b49\u5f85\u51e0\u5fae\u5999\uff09\uff0c \u5728\u4e0b\u6b21\u9891\u7387\u66f4\u65b0\u4ee5\u540e\u5728\u8bfb\u53d6\u3002 <br \/>\u4f60\u73b0\u5728\u7684\u903b\u8f91\u5c31\u662f\u4e00\u4e2a\u6b7b\u5faa\u73af\u4e00\u76f4\u8bfb\uff0c \u8fd9\u6837\u5c31\u80af\u5b9a\u662f\u4e0d\u4f1a\u91ca\u653e cpu\uff0c \u5982\u679c\u4f60\u662f\u8fd9\u6837\u6a21\u5f0f\u7684\uff0c\u90a3\u5c31\u4f7f\u7528\u72ec\u5360\u4e00\u4e2a cpu \u7684\u65b9\u5f0f\uff0c \u6bd4\u5982\u4f60\u662f 16 \u6838\u7684\u670d\u52a1\u5668\uff0c\u4f60\u5c31\u5355\u72ec\u62ff\u51fa 1-2 \u4e2a\u6838\u5355\u72ec\u8ba1\u7b97\u4f60\u7684\u56fe\u5f62\u6570\u636e\u3002 \u6216\u8005\u5355\u72ec\u62ff\u4e00\u4e2a\u670d\u52a1\u5668\u8ba1\u7b97\u56fe\u5f62\uff0c\u3000 UI \u663e\u793a\u7528\u5176\u4ed6\u7684\u673a\u5668\u663e\u793a\uff0c \u901a\u8fc7 tcp \u63a8\u9001\u7684\u65b9\u5f0f\uff0c\u76f4\u63a5\u628a\u8ba1\u7b97\u597d\u7684\u6570\u636e\u53d1\u5230\u524d\u7aef\uff0c \u8fd9\u6837\u524d\u7aef\u662f\u7ed8\u56fe\u80af\u5b9a\u4e0d\u5361\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499206\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wangyz1997 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jones2000 \u662f\u7684\uff0c\u6211\u51c6\u5907\u5b66\u4e60\u4e00\u4e0b\u591a\u8fdb\u7a0b\u3002\u56e0\u4e3a\u56fe\u50cf\u5904\u7406\u672c\u6765\u5c31\u5f88\u6162\uff0c\u5e0c\u671b\u5b83\u80fd\u591f\u4ee5\u6700\u9ad8\u7684\u901f\u5ea6\u8fd0\u884c\uff0c\u6240\u4ee5\u662f\u6b7b\u5faa\u73af\u8bfb\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499207\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wangyz1997 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @imn1 \u662f\u6bcf\u4e00\u5e27\u90fd\u8981\u6355\u6349\u3002\u56e0\u4e3a\u56fe\u50cf\u7b97\u6cd5\u672c\u6765\u5c31\u6bd4\u8f83\u6162\uff08\u4e2a\u4f4d\u6570 fps \uff09\uff0c\u56e0\u6b64\u5e0c\u671b\u80fd\u591f\u5145\u5206\u53d1\u6325\u8ba1\u7b97\u80fd\u529b\u3002\u56e0\u4e3a\u4e32\u53e3\u901a\u4fe1\u6709\u4e00\u4e2a\u8d85\u65f6\u95ee\u9898\uff0c\u6240\u4ee5\u8fd9\u4e24\u4e2a\u53ea\u80fd\u5206\u5f00\u6765\u505a\u4e86\u3002\u611f\u8c22\u4f60\u7684\u56de\u590d\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499208\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nightwitch <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Python \u7531\u4e8e GIL \u7684\u5b58\u5728\uff0c\u591a\u7ebf\u7a0b\u662f\u5047\u7684\uff0c\u5b9e\u8d28\u4e0a\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u5728\u8fd0\u884c\uff0c\u53ea\u662f\u89e3\u91ca\u5668\u5728\u5207\u6362\u4efb\u52a1\u3002opencv \u7684\u90e8\u5206\u65b0\u8d77\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u6570\u636e\u4f20\u8fc7\u53bb\uff0c\u8ba1\u7b97\u5b8c\u4e86\u4ee5\u540e\u62ff\u56de\u6765\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499209\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : youngce <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @nightwitch #24 GIL \u4fdd\u8bc1\u89e3\u91ca\u5668\u540c\u65f6\u53ea\u89e3\u91ca\u4e00\u4e2a py \u7ebf\u7a0b\u7684\u4ee3\u7801\uff0c \u4f46\u662f\u5982\u679c\u8fd9\u4e2a\u7ebf\u7a0b IO \u963b\u585e\u4e86\uff0c \u89e3\u91ca\u5668\u5c31\u8df3\u5230\u5176\u5b83\u7ebf\u7a0b\u3002 \u591a\u7ebf\u7a0b\u662f\u771f\u7684\uff0c \u53ea\u4e0d\u8fc7\u7531\u4e8e GIL \u7684\u5b58\u5728\uff0c\u5bfc\u81f4\u4e86 Cpython \u4e2d\u65e0\u6cd5\u5229\u7528\u591a\u7ebf\u7a0b\u5b9e\u73b0\u591a\u6838\u5904\u7406\u5668\u5e76\u53d1\u5904\u7406 CPU \u5bc6\u96c6\u64cd\u4f5c\u3002\u6240\u4ee5\u8bf4\u5230\u5e95\uff0cpython \u7684 io \u963b\u585e\u53ef\u4ee5\u5229\u7528\u534f\u7a0b\u3001\u591a\u7ebf\u7a0b\u5b9e\u73b0\u5f02\u6b65\uff0c\u800c cpu \u5bc6\u96c6\u7684\u64cd\u4f5c\u53ea\u80fd\u4f9d\u8d56\u4e8e\u591a\u8fdb\u7a0b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499210\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : defphilip <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u628a\u6838\u5fc3\u7684\u8ba1\u7b97\u7a0b\u5e8f\uff0c\u4e32\u53e3\u8bfb\u5199\u5168\u90e8\u5c01\u88c5\u5230 C++\u4ee3\u7801\u4e0a\uff0c\u5305\u62ec\u5f00\u7ebf\u7a0b\uff0c\u7136\u540e\u901a\u8fc7\u4e8b\u4ef6\u901a\u77e5\u7684\u65b9\u5f0f\u56de\u8c03\u544a\u8bc9\u4e3b\u7ebf\u7a0b\uff0c\u8fd9\u6837\u4f60\u5c31\u53ef\u4ee5\u5728\u540c\u4e00\u4e2a\u8fdb\u7a0b\u7a7a\u95f4\u5185\u5e72\u8fd9\u4e24\u4ef6\u4e8b\u60c5\uff0c\u5e76\u4e14\u4f60\u8fd8\u80fd\u4eab\u53d7\u5230 python \u7684\u90e8\u5206\u904d\u5386<\/p>\n<p>\u53e6\u5916\u65e2\u7136\u90fd\u7528 Qt \u4e86\uff0c\u4e3a\u4f55\u4e0d\u9009\u62e9\u76f4\u63a5\u7528 C++ Qt \u5b8c\u6210\u5462\uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499211\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : weyou <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @nightwitch \u4f60\u6ca1\u6709 get \u5230\u4efb\u4f55\u4e00\u70b9\u554a\uff0cPython \u7684\u591a\u7ebf\u7a0b\u662f\u771f\u7684\uff0c\u800c\u4e14\u8fd9\u91cc\u662f Qt \u7684\u591a\u7ebf\u7a0b\uff0c\u4e5f\u662f\u771f\u7684\u3002\u7ebf\u7a0b\u5207\u6362\u81ea\u7136\u4e5f\u662f\u64cd\u4f5c\u7cfb\u7edf\u7ba1\u7406\u7684\uff0c\u800c\u4e0d\u662f Python \u89e3\u91ca\u5668\u3002\u53ea\u662f CPU \u5bc6\u96c6\u578b\u64cd\u4f5c\u4e0b\u56e0\u4e3a GIL \u7684\u5b58\u5728\uff0c\u5bfc\u81f4\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u9700\u8981\u83b7\u53d6\u5230 GIL \u624d\u80fd\u8fd0\u884c\uff0c\u57fa\u672c\u201c\u7b49\u4ef7\u4e8e\u201d\u7ebf\u6027\u6267\u884c\u7684\uff0c\u4f46\u4e0d\u662f\u4f60\u7406\u89e3\u7684\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u5b58\u5728\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499212\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : enrio <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             CPU \u5bc6\u96c6\u578b+Python+\u591a\u7ebf\u7a0b=&gt;\u591a\u8fdb\u7a0b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1499213\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wangyz1997 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @defphilip \u6709\u4e00\u4e9b\u5e93\u53ea\u6709 Python \u6709\uff0c\u82e5\u662f\u91cd\u505a\u8f6e\u5b50\u592a\u8d39\u65f6\u8d39\u529b\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6c42\u52a9\uff1a PyQt5 \u7684\u4e00\u4e2a\u7ebf\u7a0b\u5360\u7528&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\/85865"}],"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=85865"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/85865\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=85865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=85865"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=85865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}