eventlet.monkey_patch是否影响threading
celery5.2.1以下版本任务调用多耗费1秒

eventlet如何绿化pyserial最好

妙音 posted @ 2021年3月24日 19:19 in python with tags eventlet pyserial , 606 阅读
 

问题

 
pyserial访问windows中的串口,如何绿化?不阻塞协程? 效率最高? 绿化毫无疑问要借用tpool.execute.
 
代码该如何实现才最佳呢?
 

方法一: 直接recv

 
直接recv,会阻塞协程
 
缺点: 协程被阻塞,程序不可用
 

方法二: tpool+in_waiting判断

 
import serial
from eventlet import tpool
class SerialSocket(serial.Serial):
    def recv(self):
        # 读完
        if self.in_waiting:
            return tpool.execute(self.read, self.in_waiting)
        return data

def listen_message():
    ss = SerialSocket("com10")
    buffer = b''
    while True:
        data = ss.recv()
        if data is not None:
            buffer +=data
 
缺点: cpu利用率较高
 

方法三: tpool+in_waiting判断+sleep

 
import serial
from eventlet import tpool, sleep
class SerialSocket(serial.Serial):
    def recv(self):
        # 读完
        if self.in_waiting:
            return tpool.execute(self.read, self.in_waiting)
        return data

def listen_message():
    ss = SerialSocket("com10")
    buffer = b''
    while True:
        data = ss.recv()
        if data is not None:
            buffer +=data
        else:
            sleep(0.01)
 
缺点: 满足大部分需求, 对时间要求比较敏感的程序,还是不行,多了0.01秒
 

方法四(完美):tpool+in_waiting判断+read(1)阻塞

 
利用serial的read()阻塞特性,加上tpool线程,最终线程阻塞转换成协程阻塞
 
import serial
from eventlet import tpool

class SerialSocket(serial.Serial):
    def recv(self):
        # 等待
        data = tpool.execute(self.read, 1)
        # 读完
        while self.in_waiting:
            data += tpool.execute(self.read, self.in_waiting)
        return data

def listen_message():
    ss = SerialSocket("com10")
    buffer = b''
    while True:
        g = evenlet.spawn(ss.recv)
        data = g.wait()
        buffer +=data
 
 
Avatar_small
tipandroid 说:
2021年4月02日 00:54

Well, this got me thinking what other workouts are good for those of us who find ourselves on the road or have limited equipment options.

Avatar_small
Digital_Zone 说:
2021年4月07日 17:57

The content is utmost interesting! I have completely enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great, and your efforts are outstanding! Warmtepompen

Avatar_small
Digital_Zone 说:
2021年4月07日 18:06

Thank you again for all the knowledge you distribute,Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting you site since I always come across interesting articles like this one.Great Job, I greatly appreciate that.Do Keep sharing! Regards, Airco installatie

Avatar_small
Digital_Zone 说:
2021年4月07日 18:11

Efficiently written information. It will be profitable to anybody who utilizes it, counting me. Keep up the good work. For certain I will review out more posts day in and day out. Spouwmuurisolatie Laarne

Avatar_small
Digital_Zone 说:
2021年4月07日 18:18

Wow, What an Outstanding post. I found this too much informatics. It is what I was seeking for. I would like to recommend you that please keep sharing such type of info.If possible, Thanks. Koelinstallatie

Avatar_small
Digital_Zone 说:
2021年4月07日 18:23

Wow, cool post. I’d like to write like this too – taking time and real hard work to make a great article… but I put things off too much and never seem to get started. Thanks though. Spouwmuurisolatie Lebbeke

Avatar_small
Digital_Zone 说:
2021年4月07日 18:28

Yes, I am entirely agreed with this article, and I just want say that this article is very helpful and enlightening. I also have some precious piece of concerned info !!!!!!Thanks. Koeltechnieken

Avatar_small
Digital_Zone 说:
2021年4月07日 18:33

Nice post. I was checking constantly this blog and I’m impressed! Extremely useful info specially the last part I care for such information a lot. I was seeking this certain info for a long time. Thank you and good luck. Spouwmuurisolatie Lede

Avatar_small
Digital_Zone 说:
2021年4月07日 18:38

Excellent post. I was reviewing this blog continuously, and I am impressed! Extremely helpful information especially this page. Thank you and good luck. Vriescel

Avatar_small
Digital_Zone 说:
2021年4月07日 18:42

Pretty good post. I have just stumbled upon your blog and enjoyed reading your blog posts very much. I am looking for new posts to get more precious info. Big thanks for the useful info. Spouwmuurisolatie Lierde

Avatar_small
Digital_Zone 说:
2021年4月07日 18:50

You have a real talent for writing unique content. I like how you think and the way you express your views in this article. I am impressed by your writing style a lot. Thanks for making my experience more beautiful. Koelcel

Avatar_small
Digital_Zone 说:
2021年4月07日 18:56

Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. Spouwmuurisolatie Lievegem

Avatar_small
Digital_Zone 说:
2021年4月07日 19:10

Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information. Lucht-water warmtepomp

Avatar_small
Digital_Zone 说:
2021年4月07日 19:18

I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. Spouwmuurisolatie Lochristi

Avatar_small
Digital_Zone 说:
2021年4月07日 19:23

Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. There tend to be not many people who can certainly write not so simple posts that artistically. Continue the nice writing Horeca koeling

Avatar_small
Digital_Zone 说:
2021年4月07日 19:29

Superior post, keep up with this exceptional work. It's nice to know that this topic is being also covered on this web site so cheers for taking the time to discuss this! Thanks again and again! Spouwmuurisolatie Lokeren

Avatar_small
Digital_Zone 说:
2021年4月07日 22:30

I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. Airco

Avatar_small
Digital_Zone 说:
2021年4月07日 22:40

This article is an appealing wealth of informative data that is interesting and well-written. I commend your hard work on this and thank you for this information. You’ve got what it takes to get attention. Spouwmuurisolatie Maarkedal

Avatar_small
Digital_Zone 说:
2021年4月07日 22:47

I was surfing net and fortunately came across this site and found very interesting stuff here. Its really fun to read. I enjoyed a lot. Thanks for sharing this wonderful information. Warmtepomp installatie

Avatar_small
Digital_Zone 说:
2021年4月07日 22:52

I think this is an informative post and it is very beneficial and knowledgeable. Therefore, I would like to thank you for the endeavors that you have made in writing this article. All the content is absolutely well-researched. Thanks... Spouwmuurisolatie Melle

Avatar_small
Digital_Zone 说:
2021年4月07日 22:57

Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day! Prijs airco

Avatar_small
Digital_Zone 说:
2021年4月07日 23:02

An fascinating discussion is value comment. I think that it is best to write extra on this matter, it won’t be a taboo topic however generally people are not enough to talk on such topics. To the next. Cheers Spouwmuurisolatie Maldegem

Avatar_small
Digital_Zone 说:
2021年4月07日 23:08

Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. Reiki Limburg

Avatar_small
Digital_Zone 说:
2021年4月07日 23:14

Whenever I have some free time, I visit blogs to get some useful info. Today, I found your blog with the help of Google. Believe me; I found it one of the most informative blog. Spouwmuurisolatie Moerbeke

Avatar_small
Digital_Zone 说:
2021年4月07日 23:20

Thanks a lot for sharing this excellent info! I am looking forward to seeing more posts by you as soon as possible! I have judged that you do not compromise on quality. Webdesign

Avatar_small
Digital_Zone 说:
2021年4月07日 23:27

You have a real talent for writing unique content. I like how you think and the way you express your views in this article. I am impressed by your writing style a lot. Thanks for making my experience more beautiful. Spouwmuurisolatie Merelbeke

Avatar_small
우리카지노 说:
2021年4月12日 00:38

A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one

Avatar_small
voyance 说:
2021年5月24日 13:16

Well, this got me thinking what other workouts are good for those of us who find ourselves on the road or have limited equipment options. voyance

Avatar_small
erum 说:
2021年6月15日 19:11

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon. <a href="https://zionljjtc.sharebyblog.com/4018973/drinking-tumblers-restaurant-quality-fundamentals-explained">everyday glassware</a>

Avatar_small
Buy 4FA Turbo Molly 说:
2021年6月16日 01:53

I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read !! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site. Buy 4FA Turbo Molly

Avatar_small
erum 说:
2021年6月17日 18:10

Very informative post ! There is a lot of information here that can help any business get started with a successful social networking campaign ! 에볼루션카지노

Avatar_small
dfg` 说:
2021年9月11日 21:30

Fabulous post, you have denoted out some fantastic points, I likewise think this s a very wonderful website. I will visit again for more quality contents and also, recommend this site to all. Thanks. lepto sports apk

Avatar_small
dfg` 说:
2021年9月13日 14:19

All your hard work is much appreciated. Nobody can stop to admire you. Lots of appreciation. 먹튀검증사이트

Avatar_small
dfg` 说:
2021年9月19日 22:29

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Instagram++

Avatar_small
dfg` 说:
2021年9月25日 01:23

Pubg Mobile Lite Official Redeem Code: If you are looking for the active PUBG Mobile Redeem Code 2021, then you have come to visit NewsGater. Here, we publish PUBG Lite Redeem Code Today and regularly. All working PUBG mobile lite redeem code listed on this website.

Avatar_small
dfg` 说:
2021年9月25日 23:58

I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. blackpods pro

Avatar_small
dfg` 说:
2021年9月27日 20:55

Outstanding article! I want people to know just how good this information is in your article. Your views are much like my own concerning this subject. I will visit daily your blog because I know. It may be very beneficial for me. https://blackpods.org/product/blackpods-2/

Avatar_small
erum 说:
2021年9月29日 01:23

I am looking for and I love to post a comment that "The content of your post is awesome" Great work! vape shop near me

Avatar_small
erum 说:
2021年9月29日 02:22

I am looking for and I love to post a comment that "The content of your post is awesome" Great work! 防火材料

Avatar_small
Dr.Billa 说:
2021年12月11日 06:15

Thanks for the marvelous post! ✅ I really enjoyed reading it, you might be a great author. I will certainly bookmark your blog and definitely will come back sometime soon. I want to encourage you to continue your great writing 온라인바카라

Avatar_small
Dr.Billa 说:
2022年1月12日 06:17

Good day! I could have sworn I’ve been to this site before but after going through some of the articles I realized it’s new to me. Anyhow, I’m certainly delighted I came across it and I’ll be bookmarking it and checking back frequently nclex practice test

Avatar_small
Dr.Billa 说:
2022年2月18日 05:23

Online Hold'em Community in Korea 텍사스홀덤 

Avatar_small
Dr.Billa 说:
2022年2月23日 12:40

Bolaku Situs Bandar Bola Agen Judi Online Terpercaya , Bolaku merupakan situs bandar bola resmi yang telah diakui berbagai agen dunia asia tepatnya di Indonesia dengan menyediakan pasaran taruhan judi online hingga puluhan tipe game terlengkap. bolaku

Avatar_small
Dr.Billa 说:
2022年3月01日 23:40

The Netgear extenders can be used to increase the coverage area. Network. The Netgear extender setup is highly effective. Double their wireless network range. If you have any problems, however, problem with how to setup a netgear wifi extender, you can call on toll free and take technical assistance from experts. 192.168.1.250

Avatar_small
Dr.Billa 说:
2022年3月18日 07:59

Great post, I want to thank you for this informative read; I really appreciate sharing this great post. Keep up the good work! joker สล็อต

Avatar_small
Dr.Billa 说:
2022年3月22日 02:17

You make so many great points here that I read your article a couple of times. This is great content for your readers. ufabet เข้าสู่ระบบ

Avatar_small
cyber 说:
2022年4月14日 06:52

Thanks for the marvelous post! ✅ I really enjoyed reading it, you might be a great author. I will certainly bookmark your blog and definitely will come back sometime soon. I want to encourage you to continue your great writing 작업대출사이트

Avatar_small
cyber 说:
2022年5月04日 06:29

สล็อต สล็อตออนไลน์ เกมสล็อต เว็บสล็อต สล็อต เล่น ฟรี สล็อต 888 สล็อตออนไลน์ มือ ถือ เกมสล็อต ทดลองเล่นสล็อต สล็อต

Avatar_small
Dr.Billa 说:
2022年5月26日 10:37

Thanks for the marvelous post! ✅ I really enjoyed reading it, you might be a great author. I will certainly bookmark your blog and definitely will come back sometime soon. I want to encourage you to continue your great writing strap-on

Avatar_small
Dr.Billa 说:
2022年6月04日 05:30

Nice post ✅. I was checking constantly this blog and I am impressed! Extremely helpful information specially the last part 다음드최신주소

Avatar_small
Dr.Billa 说:
2022年6月05日 11:43

Play Slope Unblocked game at your school. Control the ball in pixel world and collect a lot of points. slope game unblocked

Avatar_small
DA 说:
2022年6月07日 12:26

Joker123 provides hundreds of online slot games that are strictly regulated by Joker Gaming to provide the best gaming experience for you. https://myjoker123.com/

Avatar_small
Dr.Billa 说:
2022年6月10日 04:31

mtpolice.kr provides sports betting information, sports analysis, and sports tips as a sports community.먹튀

Avatar_small
Dr.Billa 说:
2022年6月13日 10:14

Buy fresh Garlic online on lowest prices this link

Avatar_small
cyber 说:
2022年6月15日 22:19

This article was written by a real thinking writer✅. I agree many of the with the solid points made by the writer of เน็ตทรู

 

 

 

 

Great post, I want to thank you for this informative read; I really appreciate sharing this great post. Keep up the good work! เน็ตทรูรายเดือน

 

 

 

 

 

Superior post keeps up with this exceptional work✅. It's nice to know that this topic is being also covered on this web site so cheers for taking the time to discuss this! Thanks again and again! สมัครเน็ตทรูรายเดือน

 

 

 

 

Thanks for this great post, I find it very interesting and very well thought out and put together. I look forward to reading your work in the future. เน็ตทรูรายสัปดาห์

 

 

 

 

 

Thanks for the marvelous post! ✅ I really enjoyed reading it, you might be a great author. I will certainly bookmark your blog and definitely will come back sometime soon. I want to encourage you to continue your great writing เน็ตทรูรายวัน

 

 

 

 

 

Everything is very open with a very clear description of the challenges. It was definitely informative. Your website is very helpful. Thanks for sharing On that website page, you'll see your description, why not read through this เน็ตทรูรายวัน ไม่ลดสปีด

 

 

 

 

 

Great work✅ This is the type of information that should be shared around the web. I also have some information related to on my website สมัครเน็ตทรู

 

 

 

 

 

 

Pretty nice post. I just stumbled upon your weblog and wanted to say that I have really enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again soon! เน็ตทรูรายเดือน

 

 

 

 

 

 

Fabulous post✅ you have denoted out some fantastic points regarding ไม่ลดสปีด สมัครเน็ตทรูรายเดือน

 

 

 

 

 

 

 

​What a fantabulous post ✅. Never seen this kind of useful post. I am grateful to you and expect more number of posts like these. Thank you very much เน็ตทรูรายสัปดาห์

Avatar_small
cyber 说:
2022年6月16日 11:40

The polar fleece used has been hand picked for its luxurious comfort but also for its printing qualities and most people are astonished when they see how realistic photos look when they are printed on the front of the blanket fleece. this link

 

 

 

 

 

 

 

 

 

 

​We publish daily results of the biggest lottery in India called the Lottery Sambad. It is also called Dear Lottery. Dear Lottery

Avatar_small
Dr.Billa 说:
2022年6月18日 04:39

These very small facts are produced using wide range of qualifications✅ I favor the idea such a good deal. This specific seems to be definitely excellent เน็ตทรูรายวัน

 

 

 

 

 

This was really very informative site for me I really liked it I felt very happy while reading this site เน็ตทรูรายวัน ไม่ลดสปีด

 

 

 

 

 

 

I prefer merely excellent resources and you can see these in เน็ตทรูรายวัน ไม่ลดสปีด

 

 

 

 

 

 

 

You amazingly have terrific article content. Cheers for sharing your blog site. Thank you for sharing this เน็ตทรูรายเดือน

 

 

 

 

 

 

 

Wow, What an Outstanding post✅. I found this too much informatics. It is what I was seeking for เน็ตทรูรายสัปดาห์

 

 

 

 

 

 

 

Excellent article. I want to thank you for this informative read; I really appreciate sharing this great post. Keep up your work! เน็ตทรูรายอาทิตย์ ไม่ลดสปีด

 

 

 

 

 

 

 

 

It’s really a fantastic website ✅ thanks for sharing. There's no doubt I would fully rate it after i read what the idea about this article is โปรเน็ต AIS

 

 

 

 

 

 

 

 

 

Hi there! You make so many good points here that I read your article a couple of times. This is really nice content for your readers. เน็ต ais รายสัปดาห์

 

 

 

 

 

 

 

 

 

 

I found useful information on this topic✅. Thank you posting relative information and its currently becoming easier to complete this project เน็ต ais รายเดือน

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Good day! I could have sworn I’ve been to this site before but after going through some of the articles I realized it’s new to me. Anyhow, I’m certainly delighted I came across it and I’ll be bookmarking it and checking back frequently aw8

Avatar_small
cyber 说:
2022年6月18日 20:46

This is a great article and great read for me✅. It's my first visit to your blog aw8

 

 

 

 

I am hoping that you will continue writing this kind of blog. Thanks for sharing this information. aw8

 

 

 

 

 

This Post is providing valuable and unique information✅ I know that you take a time and effort to make a awesome article ut9winth

 

 

 

 

 

I enjoyed reading this post such an interesting info post. Thanks for providing good info on the topic of ut9winth

 

 

 

 

 

Everything has its own value, but this is really precious information✅ shared by Author of ut9winth

 

 

 

 

I appreciate your efforts in preparing this post. I really like your blog articles on happyluke

 

 

 

 

 

What a fantabulous post ✅. Never seen this kind of useful post. I am grateful to you and expect more number of posts like these. Thank you very much happyluke

 

 

 

 

Fabulous post✅ you have denoted out some fantastic points regarding happyluke

 

 

 

 

 

Pretty nice post. I just stumbled upon your weblog and wanted to say that I have really enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again soon! jbo

 

 

 

 

 

​Great work✅ This is the type of information that should be shared around the web. I also have some information related to on my website jbo

Avatar_small
cyber 说:
2022年6月26日 22:48

Online poker information community in Korea 텍사스홀덤

Avatar_small
cyber 说:
2022年6月30日 22:16

Pretty nice post. I just stumbled upon your weblog and wanted to say that I have really enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again soon! Teesside University

Avatar_small
cyber 说:
2022年7月08日 00:09

Wow, What an Outstanding post✅. I found this too much informatics. It is what I was seeking for 온라인바둑이

Avatar_small
bangalitantrik 说:
2022年7月08日 17:51

Excellent Article!!! I like the helpful information you provide in your article.

Avatar_small
바카라사이트 说:
2022年7月30日 14:44

I think this site has got some very excellent info for everyone 바카라사이트 카지노사이트

Avatar_small
aqsa 说:
2022年8月03日 05:30

Superb blog post, I have book marked this internet site so ideally I’ll see much more on this subject in the foreseeable future https://totoworld24.com

Avatar_small
dark web/deep web/d 说:
2022年8月07日 15:11

The FBI and other law enforcement agencies are constantly working to find ways to close the hole known as the dark web.  dark web links

Avatar_small
dark web/deep web/d 说:
2022年8月07日 15:33

They have come up with a list of several methods that they claim are effective against people involved in web site link trading. The most popular technique they suggest is the use of criminal records and criminal history checks.  deep web

Avatar_small
dark web/deep web/d 说:
2022年8月07日 16:00

By making a little effort to protect the links on your sites, you can save yourself from the dark. This may not be enough to prevent cyber-criminals from getting onto your sites, but it is definitely a good place to start.  dark web links

Avatar_small
dark web/deep web/d 说:
2022年8月07日 16:22

So before you proceed with this, make sure you're using the right tools. First, visit some search engine that features CC services such as Google, Yahoo, or MSN. dark web sites

Avatar_small
dark web/deep web/d 说:
2022年8月07日 16:41

However, you should not rely solely on these link research tools. You should also use the right tools when you have found a dark web link that points to a pornographic site.  dark web

Avatar_small
dark web/deep web/d 说:
2022年8月07日 16:59

The entire process of how to start affiliate marketing with ClickBank is pretty simple. You don't even need a website to be part of the affiliate program. All you need is to create a sales page, drive traffic to the sales page, and get customers to order.  work from home jobs

Avatar_small
dark web/deep web/d 说:
2022年8月07日 17:22

Just like with anything else on the Internet, there are people who will be willing to buy your affiliate products. When someone clicks on your link, you earn a commission. Pretty simple, right? affiliate marketing success

Avatar_small
aqsa 说:
2022年8月09日 08:10

Royalgreen by Allgreen Properties Limited. Hotline 61004343. Get Discounts, Direct Developer Price, Floor Plan, Price List, Brochure & More. royalgreen condo


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter