wsgi

How can I use an app-factory in Flask / WSGI servers and why might it be unsafe?

断了今生、忘了曾经 提交于 2019-12-18 10:22:17
问题 A question on app callables, WSGI servers and Flask circular imports I am (possibly) confused. I want to safely create Flask / WSGI apps from app-factories and still be able to use them in WSGI servers easily. tl;dr Can I safely avoid creating an app on import of init (as recommended)and instead create it later (ie with a factory method) How do I make that app work neatly with a WSGI server? Especially when I am passing in the config and other settings not pulling them from ENV For example::

URL building with Flask and non-unique handler names

我只是一个虾纸丫 提交于 2019-12-18 10:14:23
问题 Flask provides a url_for function to generate URLs to handlers based on the URL pattern. But this would imply that the handler functions must have unique names across the entire application. Is that correct? Example Module A has a handler index : @app.route('/') def index(): pass And Module B has another handler index : @app.route('/anotherindex') def index(): pass How to distinguish the handlers called index when building URLs? url_for('index') 回答1: I don't know how you could do with all the

How do I copy wsgi.input if I want to process POST data more than once?

吃可爱长大的小学妹 提交于 2019-12-18 07:52:22
问题 In WSGI, post data is consumed by reading the file-like object environ['wsgi.input'] . If a second element in the stack also wants to read post data it may hang the program by reading when there's nothing more to read. How should I copy the POST data so it can be processed multiple times? 回答1: Go have a look at WebOb package. It provides functionality that allows one to designate that wsgi.input should be made seekable. This has the effect of allowing you to rewind the input stream such that

AWS Elastic Beanstalk - Script timed out before returning headers: application.py

折月煮酒 提交于 2019-12-17 22:34:05
问题 I have an existing Elastic Beanstalk flask app on AWS that occasionally will not initialize and gives the following error: [Mon Jan 23 10:06:51.550205 2017] [core:error] [pid 7331] [client 127.0.0.1:43790] script timed out before returning headers: application.py [Mon Jan 23 10:10:43.910014 2017] [core:error] [pid 7329] [client 127.0.0.1:43782] End of script output before headers: application.py Any ideas why this might be? Most recently I changed the project's requirements.txt to include

Multiple mod_wsgi apps on one virtual host directing to wrong app

给你一囗甜甜゛ 提交于 2019-12-17 21:46:24
问题 I'm trying to get two (or more) Django applications set up at subdirectories under the same domain, e.g.: http://example.com/site1/ http://example.com/site2/ I know that normally this works fine by setting up an apache virtualhost like this: <VirtualHost *:80> ... WSGIScriptAlias /site1 /path/to/site1.wsgi WSGIScriptAlias /site2 /path/to/site2.wsgi </VirtualHost> Now, I've verified that each site works individually. But when I try to run both side-by-side, apache sends me to whichever site

Why does running Flask with Nginx require a WSGI wrapper?

时光怂恿深爱的人放手 提交于 2019-12-17 20:21:41
问题 So from the Python/Flask docs, they both recommend not running the Flask web server as the production web server which makes sense. My question is, am I then able to run my Flask application on top of an Nginx server? Why do all the guides on the internet recommend wrapping Flask around uWSGI, Tornado, or some other WSGI server? What does it mean for something to be WSGI? Isn't Flask WGSI compliant? I am particularly lost because here, the first response states: Apache and Nginx are both HTTP

Non-blocking concurrent wsgi server

核能气质少年 提交于 2019-12-17 19:52:06
问题 I am trying to be able to respond incoming web requests simultaneously, while processing of a request includes quite long IO call. I'm going to use gevent, as it's supposed to be "non-blocking" The problem I found is that requests are processed sequentially even though I have a lot of gevent threads. For some reason requests get served by single green thread. I have nginx (with default config which isn't relevant here I think), also I have uwsgi and simple wsgi app that emulates IO-blocking

WSGI file streaming with a generator

痴心易碎 提交于 2019-12-17 19:17:10
问题 I have the following code: def application(env, start_response): path = process(env) fh = open(path,'r') start_response('200 OK', [('Content-Type','application/octet-stream')]) return fbuffer(fh,10000) def fbuffer(f, chunk_size): '''Generator to buffer file chunks''' while True: chunk = f.read(chunk_size) if not chunk: break yield chunk I'm not sure that it's right but the scraps of information I've found on the internet have led me to think it ought to work. Basically I want to stream a file

How can I tell whether my Django application is running on development server or not?

江枫思渺然 提交于 2019-12-17 15:39:34
问题 How can I be certain that my application is running on development server or not? I suppose I could check value of settings.DEBUG and assume if DEBUG is True then it's running on development server, but I'd prefer to know for sure than relying on convention. 回答1: server = request.META.get('wsgi.file_wrapper', None) if server is not None and server.__module__ == 'django.core.servers.basehttp': print('inside dev') Of course, wsgi.file_wrapper might be set on META, and have a class from a module

Make sure only one worker launches the apscheduler event in a pyramid web app running multiple workers

那年仲夏 提交于 2019-12-17 15:25:48
问题 We have a web app made with pyramid and served through gunicorn+nginx. It works with 8 worker threads/processes We needed to jobs, we have chosen apscheduler. here is how we launch it from apscheduler.events import EVENT_JOB_EXECUTED, EVENT_JOB_ERROR from apscheduler.scheduler import Scheduler rerun_monitor = Scheduler() rerun_monitor.start() rerun_monitor.add_interval_job(job_to_be_run,\ seconds=JOB_INTERVAL) The issue is that all the worker processes of gunicorn pick the scheduler up. We