Path: csiph.com!news.swapon.de!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 10:09:58 +1100 Lines: 38 Message-ID: References: <44d92f52-4f92-470d-a724-102a14d185de@googlegroups.com> <3e30fc58-4460-40a6-a639-22cd4d406f0b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de iX/crQQdW+oMhOMt8toBXwp5eYw+F/BcTZ3TFSkvE0pA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'broken': 0.03; 'received:209.85.223': 0.03; 'subject:Python': 0.05; 'caller': 0.07; 'socket': 0.07; 'variable,': 0.07; 'cc:addr:python-list': 0.09; 'cookies,': 0.09; 'php,': 0.09; 'question?': 0.09; 'stored': 0.10; 'python': 0.10; '(unlike': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sessions,': 0.16; 'sits': 0.16; 'subject:perspective': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '(see': 0.20; 'saying': 0.22; 'am,': 0.23; 'dec': 0.23; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; 'message-id:@mail.gmail.com': 0.27; 'disk': 0.27; 'looks': 0.29; 'preserve': 0.29; 'request,': 0.29; 'restart': 0.29; 'reset': 0.29; 'program,': 0.29; 'normally': 0.30; 'another': 0.32; 'says': 0.32; 'related': 0.32; 'directory,': 0.33; 'maintaining': 0.34; 'tue,': 0.34; 'server': 0.34; 'gives': 0.35; 'received:google.com': 0.35; 'next': 0.35; 'appearance': 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'client': 0.37; 'skip:5 10': 0.37; 'received:209': 0.38; 'anything': 0.38; 'goes': 0.39; 'does': 0.39; 'subject:from': 0.39; 'waiting': 0.60; 'your': 0.60; 'back': 0.62; 'information': 0.63; 'between': 0.65; 'request.': 0.66; 'state,': 0.66; "they're": 0.66; 'talking': 0.67; 'feeling': 0.72; 'state.': 0.72; '"hey,': 0.84; '"it': 0.84; 'chrisa': 0.84; 'openly': 0.84; 'simulation.': 0.84; 'wipe': 0.84; 'to:none': 0.91; 'different.': 0.91; 'relate': 0.91 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=43/Kt4fjCLpIZkZTKvMzeK8n7Ld2tiRb85WacAjIbVQ=; b=WJ56lAjcxYkjpLKxQBzyD1BO5B072CLeg/+PN+LdBnBsyxnauvLoDLokfnNps3EgaJ a2SqBH/Kzg9xDu6JGwLjODVQtS+rJetFjYNrzqjBA3QbX/kGfBEwwzjxaOHRQyrxQqy2 a2l9M1XKvmGth2zIndjRXX5SLJW+EFV6ZnAMoOyGLS6pFg8prg6mYZN3c1KVTnEChtzs FypYWdgLwwh54wQoczqdODf375fRkKtbkNR8IY3Lu53BEcEa0OiHdokPGdqstlhqZQGd FMf22AAg8nOEL3qb51UQDLXMFXHrBoonfrKmx5A2Q6pR8CT0Xw5gWkJZ5y33r6a2IpDd /1hg== X-Received: by 10.107.10.233 with SMTP id 102mr892112iok.31.1449529798656; Mon, 07 Dec 2015 15:09:58 -0800 (PST) In-Reply-To: <3e30fc58-4460-40a6-a639-22cd4d406f0b@googlegroups.com> 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:100117 On Tue, Dec 8, 2015 at 9:27 AM, wrote: > In regards to Chris's statement: "It openly and honestly does NOT reset its state between page requests" > > With PHP, I have sessions to preserve state. I have a feeling that this is significantly different. Yes? How? Does this somehow relate to how websockets are implemented? 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. 2) Sessions, cookies, and related concepts. A request comes in, and the response goes out "Hi! You're caller number 52635686412, and your call is important to us". Another request comes in from the same web browser, and the browser says "Hi! You said I was caller number 52635686412". The server looks up its information about that caller, which might be in a database, or on disk in the /tmp directory, or stored in process state (see above), or anything at all. This gives the appearance of per-client state, but it's all a simulation. 3) Websockets. A client makes a request saying "Hey, I want a websocket, please". The server says "Sure", and then they start maintaining true state. The socket would be broken if either the server or the client restarts (unlike sessions, although normally they're set up so a client restart will wipe the session). Websocket state is per-connection. Does that answer your question? The one I was talking about there was #1, process state. ChrisA