Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Understanding Python from a PHP coder's perspective Date: Tue, 8 Dec 2015 14:47:40 +1100 Lines: 29 Message-ID: References: <44d92f52-4f92-470d-a724-102a14d185de@googlegroups.com> <3e30fc58-4460-40a6-a639-22cd4d406f0b@googlegroups.com> <20151207211114.49a82ef3@bigbox.christie.dr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de AABKK99RWJoA9CJ2Fwf1cQwS3/yr0rwQRIWB2ImjqBzA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'subject:Python': 0.05; 'cache': 0.05; 'variable,': 0.07; 'cc:addr:python-list': 0.09; 'cookies,': 0.09; 'python': 0.10; 'instead.': 0.15; 'bugs,': 0.16; 'caches': 0.16; 'dropping': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'globals.': 0.16; 'key/value': 0.16; 'received:209.85.223.173': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sits': 0.16; 'stuff,': 0.16; 'subject:perspective': 0.16; 'wrote:': 0.16; 'else,': 0.18; 'load': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '(you': 0.23; 'dec': 0.23; 'tim': 0.24; 'header:In-Reply-To:1': 0.24; 'sense': 0.26; 'chris': 0.26; 'message-id:@mail.gmail.com': 0.27; 'idea': 0.28; '(it': 0.29; 'chase': 0.29; 'etc).': 0.29; 'request,': 0.29; 'program,': 0.29; 'etc.)': 0.32; 'tue,': 0.34; 'info': 0.34; 'received:google.com': 0.35; 'next': 0.35; 'something': 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'goes': 0.39; 'subject:from': 0.39; 'where': 0.40; 'waiting': 0.60; 'your': 0.60; 'real': 0.62; 'back': 0.62; 'yes': 0.62; 'lose': 0.63; 'goal': 0.64; 'request.': 0.66; 'state,': 0.66; 'state.': 0.72; 'life.': 0.81; 'chrisa': 0.84; 'implications': 0.84; 'to:none': 0.91; 'different.': 0.91; 'sitting': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=kSPjpPxNfI5BZq8j8Rs1lBlm/MEmbca1Nl148LYKzaU=; b=J0l1SVffnd6tayE3g/G9/WPlm0VlXkPhmmYq5zP7f4A7rO7TeCOkOHhRSpWssXeuwN PX9h4QBma4+0qCr00KLso/9cOpxU4yrAKLCBFATd93JmY1anGlULLnt0KpjZjaWZNiV2 GbFrr+Kq4nXJ6xYuVNAwy1+dGcavSBcZwA8R5d3+itGaT6bwlVpS5UPMIa6Fv/89xsKI rekieZqgcXXM8fkvMwBwfhtqZ3vmOmQsX9cDzNuLeJ391n+a9/47eBV8VWwS0Pte9Yhp QJcpChOg8wDXTP2D4XLgmaqMyp4wRSovWP1gNx6LdUTE8UUivln+HTD5xOh/wP0DNRXA 1U5A== X-Received: by 10.107.16.84 with SMTP id y81mr1717732ioi.19.1449546460487; Mon, 07 Dec 2015 19:47:40 -0800 (PST) In-Reply-To: <20151207211114.49a82ef3@bigbox.christie.dr> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100134 On Tue, Dec 8, 2015 at 2:11 PM, Tim Chase wrote: > On 2015-12-08 10:09, Chris Angelico wrote: >> All three are very different. >> >> 1) Process state. >> >> You start up a Python program, and it sits there waiting for a >> request. You give it a request, and get back a response; it goes >> back to waiting for a request. If you change a global variable, or >> maintain persistent state, or anything, the next request will 'see' >> that change. This is completely global. > > 1) This is completely global *to the process* (you can have multiple > Python processes sitting around waiting, taking advantage of multiple > cores) > > 2) This is almost always a bad idea for multiple reasons (it can get > in the way of scaling, it can produce hard-to-track-down bugs, etc). > Use a real session store (a database, a key/value store like > memcached, a NoSQL store like Redis, store session info in cookies, > etc.) instead. If your goal is session state, then yes - use something that actually persists past the process life. But for caches and stuff, where dropping them has performance implications but nothing else, it makes good sense to keep them in globals. Particularly if you simply populate the cache on process load and then never lose it. ChrisA