{"id":875,"date":"2020-09-17T16:58:22","date_gmt":"2020-09-17T07:58:22","guid":{"rendered":"http:\/\/blog.marubaram.wo.tc\/?p=875"},"modified":"2020-09-17T16:58:22","modified_gmt":"2020-09-17T07:58:22","slug":"python%ec%97%90%ec%84%9c-threading-%ec%98%88%ec%a0%9c","status":"publish","type":"post","link":"https:\/\/blog.marubaram.wo.tc\/?p=875","title":{"rendered":"Python\uc5d0\uc11c Threading \uc608\uc81c"},"content":{"rendered":"\n<p>\uc2dc\ub9ac\uc5bc \ud3ec\ud2b8\ub85c \ub4e4\uc5b4\uc624\ub294 \ub370\uc774\ud130 \ucc98\ub9ac\ud558\ub294 \uac00\uc6b4\ub370 Blocking \ub54c\ubb38\uc5d0 \ubc1c\uc0dd\ud558\ub294 \uc774\uc288\uac00 \uc788\uc74c<\/p>\n\n\n\n<p>\uc6b0\uc120\uc740 \ub2e8\uc21c\ud788 non-blocking \ubaa8\ub4dc\ub85c serial \uc624\ud508\ud558\uace0, \uc815\ud574\uc9c4 byte \ub9cc \uc77d\uc5b4\uc624\ub294 \ubc29\uc2dd\uc73c\ub85c \uc218\uc815\ud574\uc11c \ub3cc\uc544\ub294 \uac00\ub294\ub370 \uc880\ub354 fancy \ud55c \ubc29\ubc95\uc774 \ubcf4\uc5ec\uc11c \uc2a4\ud06c\ub7a9<\/p>\n\n\n\n<p>Readline\uc744 \ubcc4\ub3c4\uc758 \uc2a4\ub808\ub4dc\ub85c \ube7c\ub294 \ubc29\ubc95\uc778\ub370, \uc774\ub807\uac8c\ud558\uba74 \uc815\ud574\uc9c4 \ubc14\uc774\ud2b8\uac00 \uc544\ub2c8\uc5b4\ub3c4 \ub370\uc774\ud130 \ucc98\ub9ac\ud558\ub294\ub370 \ubb38\uc81c\uac00 \uc5c6\uc744\ub4ef.. \ub098\uc911\uc5d0 \uc218\uc815\ud574\ubcf4\uc790<\/p>\n\n\n\n<p>\ucd9c\ucc98\ub294  <a href=\"https:\/\/stackoverflow.com\/questions\/17553543\/pyserial-non-blocking-read-loop\">https:\/\/stackoverflow.com\/questions\/17553543\/pyserial-non-blocking-read-loop<\/a> <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import threading\nimport serial\n\nconnected = False\nport = 'COM4'\nbaud = 9600\n\nserial_port = serial.Serial(port, baud, timeout=0)\n\ndef handle_data(data):\n    print(data)\n\ndef read_from_port(ser):\n    while not connected:\n        #serin = ser.read()\n        connected = True\n\n        while True:\n           print(\"test\")\n           reading = ser.readline().decode()\n           handle_data(reading)\n\nthread = threading.Thread(target=read_from_port, args=(serial_port,))\nthread.start()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\uc2dc\ub9ac\uc5bc \ud3ec\ud2b8\ub85c \ub4e4\uc5b4\uc624\ub294 \ub370\uc774\ud130 \ucc98\ub9ac\ud558\ub294 \uac00\uc6b4\ub370 Blocking \ub54c\ubb38\uc5d0 \ubc1c\uc0dd\ud558\ub294 \uc774\uc288\uac00 \uc788\uc74c \uc6b0\uc120\uc740 \ub2e8\uc21c\ud788 non-blocking \ubaa8\ub4dc\ub85c serial \uc624\ud508\ud558\uace0, \uc815\ud574\uc9c4 byte \ub9cc \uc77d\uc5b4\uc624\ub294 \ubc29\uc2dd\uc73c\ub85c \uc218\uc815\ud574\uc11c \ub3cc\uc544\ub294 \uac00\ub294\ub370 \uc880\ub354 fancy \ud55c \ubc29\ubc95\uc774 \ubcf4\uc5ec\uc11c \uc2a4\ud06c\ub7a9 Readline\uc744 \ubcc4\ub3c4\uc758 \uc2a4\ub808\ub4dc\ub85c \ube7c\ub294 \ubc29\ubc95\uc778\ub370, \uc774\ub807\uac8c\ud558\uba74 \uc815\ud574\uc9c4 \ubc14\uc774\ud2b8\uac00 \uc544\ub2c8\uc5b4\ub3c4 \ub370\uc774\ud130 \ucc98\ub9ac\ud558\ub294\ub370 \ubb38\uc81c\uac00 \uc5c6\uc744\ub4ef.. \ub098\uc911\uc5d0 \uc218\uc815\ud574\ubcf4\uc790 \ucd9c\ucc98\ub294 https:\/\/stackoverflow.com\/questions\/17553543\/pyserial-non-blocking-read-loop<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[336],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.marubaram.wo.tc\/index.php?rest_route=\/wp\/v2\/posts\/875"}],"collection":[{"href":"https:\/\/blog.marubaram.wo.tc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.marubaram.wo.tc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.marubaram.wo.tc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.marubaram.wo.tc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=875"}],"version-history":[{"count":1,"href":"https:\/\/blog.marubaram.wo.tc\/index.php?rest_route=\/wp\/v2\/posts\/875\/revisions"}],"predecessor-version":[{"id":876,"href":"https:\/\/blog.marubaram.wo.tc\/index.php?rest_route=\/wp\/v2\/posts\/875\/revisions\/876"}],"wp:attachment":[{"href":"https:\/\/blog.marubaram.wo.tc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.marubaram.wo.tc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.marubaram.wo.tc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}