当前位置: 动力学知识库 > 问答 > 编程问答 >

Synchronization in Python - Gevent Multithreaded Environment

问题描述:

Am a java Developer and started learning python Language, recently i came across the Python Gevent Library which is uses Asynchronous greenlets. Could somebody explain me, How synchronization, Deadlocks, live lock works/avoided in Python using Gevent.

  • In Java Threading, we have Synchronization blocks, which prevents the above issues

网友答案:

Writing concurrent applications using gevent is different from those using multithreads or multiprocesses. It allows you to write concurrent applications using synchronous logic and only one greenlet could run at a time.

If you have created many greenlets and they should visit the same resource but they don't have cooperation relationships, then you don't have to use locks to control them visiting the shared resource because there's only one greenlet could run at a time. Until the greenlet encounters some operations which could hand in the execution to the hub greenlet, it will run all the time until it returns.

If the greenlets you create have cooperation relationships, you could use locks provided by gevent as the way you use in Java.

Here's some resources which may do you a favor:

  • Concurrency & Gevent
  • gevent tutorial
  • coroutine
分享给朋友:
您可能感兴趣的文章:
随机阅读: