greenlets

Stackless in PyPy and PyPy + greenlet - differences

牧云@^-^@ 提交于 2019-12-31 10:41:12
问题 New version of PyPy ships with integrated Stackless . As far as I know the bundled Stackless is not the same as the origin Stackless from 2001 with continuations. So mainly it is the green threads framework with dispatcher. Greenlet is a spin-of Stackless which provides the Stackless green threads functionality as an extension module. Is there any benefit from using "native" Stackless from PyPy than PyPy + greenlet + some dispatcher (eg: gevent )? Or the problem is that i can't use those

Why the amount of greenlets will impact the elapsed time of the responses

独自空忆成欢 提交于 2019-12-24 18:53:22
问题 I'm using Python coroutine library gevent and monkey patch to increase the concurrency of http requests. But I noticed the elapsed time of the responses increased while the concurrency increased. Below the sample code: import gevent from gevent import monkey import requests monkey.patch_all(thread=False) def action(): resp = requests.get("https://www.google.com") if resp.status_code == 200: print resp.elapsed.total_seconds() jobs = [] for i in range(100): jobs.append(gevent.spawn(action))

Why do we need gevent.queue?

我的未来我决定 提交于 2019-12-10 21:30:12
问题 My understanding of Gevent is that it's merely concurrency and not parallelism. My understanding of concurrency mechanisms like Gevent and AsyncIO is that, nothing in the Python application is ever executing at the same time. The closest you get is, calling a non-blocking IO method, and while waiting for that call to return other methods within the Python application are able to be executed. Again, none of the methods within the Python application ever actually execute Python code at the same

Gevent blocked by flask even use monkey patch

╄→гoц情女王★ 提交于 2019-12-10 18:24:12
问题 I'm using the flask+gevent to build my server, but the gevent named 'getall' was blocked by flask, so the 'getall' function cannot print message in this code. The monkey patch is in use. import time import WSGICopyBody from flask import Flask import gevent def handle_node_request() : while True : print 'in handle_node_request' gevent.sleep(1) def getall() : print 'in getall' def create_app() : app = Flask(__name__) app.wsgi_app = WSGICopyBody.WSGICopyBody(app.wsgi_app) app.add_url_rule('/node

Access flask.g inside greenlet

二次信任 提交于 2019-12-10 01:12:12
问题 I'm using Flask + gevent and want to access the flask.g application global inside the target function of a greenlet. I'm using the copy_current_request_context decorator and have a situation pretty similar to example given in the docs: import gevent from flask import copy_current_request_context, g @app.route('/') def index(): g.user_data = 'foobar' g.more_user_data = 'baz' @copy_current_request_context def do_some_work(): some_func(g.user_data, g.more_user_data) ... gevent.spawn(do_some_work

Access flask.g inside greenlet

邮差的信 提交于 2019-12-04 23:46:46
I'm using Flask + gevent and want to access the flask.g application global inside the target function of a greenlet. I'm using the copy_current_request_context decorator and have a situation pretty similar to example given in the docs: import gevent from flask import copy_current_request_context, g @app.route('/') def index(): g.user_data = 'foobar' g.more_user_data = 'baz' @copy_current_request_context def do_some_work(): some_func(g.user_data, g.more_user_data) ... gevent.spawn(do_some_work) return 'Regular response' However, I get the following error: AttributeError: '_AppCtxGlobals' object

Making Django go green

馋奶兔 提交于 2019-12-03 10:27:19
问题 I have a Django management command that makes thousands of TCP/UDP requests. I've used Gevent to speed this up as I've restructured my code to work as coroutines. The socket connections no longer block but from what I've read, parts of Django still aren't green. (By green, I mean using greenlets.) Could you tell me what parts of Django aren't green and what I can do to make them green? There are some DB related parts that still block I think. Are there any libraries/patches for Django that

How can I write a socket server in a different thread from my main program (using gevent)?

試著忘記壹切 提交于 2019-12-02 16:53:32
问题 I'm developing a Flask/gevent WSGIserver webserver that needs to communicate (in the background) with a hardware device over two sockets using XML. One socket is initiated by the client (my application) and I can send XML commands to the device. The device answers on a different port and sends back information that my application has to confirm. So my application has to listen to this second port. Up until now I have issued a command, opened the second port as a server, waited for a response

Python and truly concurrent threads

主宰稳场 提交于 2019-12-01 17:54:27
问题 I've been reading for hours now and I can completely figure out how python multi threading is faster than a single thread. The question really stems from GIL. If there is GIL, and only one thread is really running at any single time, how can multi threading be faster than a single thread? I read that with some operations GIL is released (like writing to file). Is that what makes multi threading faster? And about greenlets. How do those help with concurrency at all? So far all the purpose I

Greenlet Vs. Threads

寵の児 提交于 2019-11-28 14:56:22
I am new to gevents and greenlets. I found some good documentation on how to work with them, but none gave me justification on how and when I should use greenlets! What are they really good at? Is it a good idea to use them in a proxy server or not? Why not threads? What I am not sure about is how they can provide us with concurrency if they're basically co-routines. Matt Joiner Greenlets provide concurrency but not parallelism. Concurrency is when code can run independently of other code. Parallelism is the execution of concurrent code simultaneously. Parallelism is particularly useful when