Giter Site home page Giter Site logo

关于协程 about interview_python HOT 4 CLOSED

taizilongxu avatar taizilongxu commented on September 27, 2024
关于协程

from interview_python.

Comments (4)

taizilongxu avatar taizilongxu commented on September 27, 2024

还是不太一样的, 协程就不需要考虑同步异步的问题了, 因为切换的问题是交给用户自己控制了

from interview_python.

lytofb avatar lytofb commented on September 27, 2024

恩,这个地方是我理解错了
参见https://segmentfault.com/a/1190000000663472
http://www.cnblogs.com/lhfcws/p/4148227.html

from interview_python.

lytofb avatar lytofb commented on September 27, 2024

线程确实比协程性能更好。因为线程能利用多核达到真正的并行计算,如果任务设计的好,线程能几乎成倍的提高你的计算能力,说线程性能不好的很多是因为没有设计好导致大量的锁、切换、等待,这些很多都是应用层的问题。而协程因为是非抢占式,所以需要用户自己释放使用权来切换到其他协程,因此同一时间其实只有一个协程拥有运行权,相当于单线程的能力。我们在x360、xbox1和ps4上做游戏的时候,开线程用来做数据加载、解压这种不需要或者很少需要数据同步的任务的时候效率杠杠的,而协程用来处理一些应用层逻辑调度的时候非常方便。官方文档也建议,协程只是为了老代码移植和兼容性,不推荐新代码使用。

from interview_python.

taizilongxu avatar taizilongxu commented on September 27, 2024

恩, 你说的对,
但是python 里算比较特殊, 因为只能用单核.
你说的官方文档是?

from interview_python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.