Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.046 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.09; 'python.': 0.02; 'scripts': 0.03; 'example:': 0.03; 'programmer': 0.03; '"this': 0.03; 'else:': 0.03; 'broken': 0.04; 'syntax': 0.04; '(even': 0.05; 'anyway.': 0.05; 'elif': 0.05; 'model,': 0.05; 'output': 0.05; 'run-time': 0.05; 'string.': 0.05; 'sufficient': 0.05; 'subject:Python': 0.06; '"""': 0.07; '*not*': 0.07; 'assignment': 0.07; 'automate': 0.07; 'context': 0.07; 'debug': 0.07; 'explicit': 0.07; 'finally:': 0.07; 'float': 0.07; 'granted,': 0.07; 'list?': 0.07; 'modifying': 0.07; 'postgresql': 0.07; 'practice,': 0.07; 'reject': 0.07; 'socket': 0.07; 'suppose': 0.07; 'url:msdn': 0.07; 'string': 0.09; '101': 0.09; 'advice.': 0.09; 'apis': 0.09; 'append': 0.09; 'blue': 0.09; 'callback': 0.09; 'creation,': 0.09; 'data):': 0.09; 'deploy': 0.09; 'finished.': 0.09; 'happen.': 0.09; 'hour.': 0.09; 'immutable': 0.09; 'incidental': 0.09; 'lawrence': 0.09; 'logic': 0.09; 'naturally': 0.09; 'next,': 0.09; 'operand': 0.09; 'pretend': 0.09; 'processing,': 0.09; 'rewrite': 0.09; 'solution,': 0.09; 'specific.': 0.09; 'terms,': 0.09; 'testing,': 0.09; 'things,': 0.09; 'thrown': 0.09; 'to)': 0.09; 'try:': 0.09; 'tune': 0.09; 'url:github': 0.09; 'runs': 0.10; 'translate': 0.10; 'url:blog': 0.10; 'api': 0.11; 'python': 0.11; 'def': 0.12; 'bug': 0.12; 'gui': 0.12; 'jan': 0.12; 'project,': 0.12; 'assume': 0.14; 'archive': 0.14; 'creates': 0.14; 'language.': 0.14; 'question.': 0.14; 'random': 0.14; 'thread': 0.14; 'changes': 0.15; 'windows': 0.15; 'tuple.': 0.16; 'url:html)': 0.16; 'win7': 0.16; 'worst': 0.16; 'around,': 0.84; 'asynchronous': 0.84; 'borrow': 0.84; 'common,': 0.84; 'compare:': 0.84; 'confusing': 0.84; 'desperately': 0.84; 'dispatching': 0.84; 'email name:steve': 0.84; 'etc),': 0.84; 'etc,': 0.84; 'excel,': 0.84; 'excel.': 0.84; 'fails,': 0.84; 'fifty': 0.84; 'forced': 0.84; 'from:addr:live.co.uk': 0.84; 'issues;': 0.84; 'it"': 0.84; "it'd": 0.84; 'killing': 0.84; 'lan.': 0.84; 'listens': 0.84; 'lying': 0.84; 'photoshop,': 0.84; 'player.': 0.84; 'pools': 0.84; 'servers:': 0.84; 'space-time': 0.84; 'stimuli.': 0.84; 'timeless': 0.84; 'toy': 0.84; 'url:%21': 0.84; 'url:lang': 0.84; 'usage;': 0.84; 'world!"': 0.84; 'worth,': 0.84; 'absolutely': 0.87; '+1000': 0.91; 'clueless': 0.91; 'dealt': 0.91; 'dozen': 0.91; 'email name:python-list-owner': 0.91; 'email name:python- list-request': 0.91; 'inefficient': 0.91; 'instantly.': 0.91; 'mistake': 0.91; 'transactions': 0.91; 'whereas': 0.91; 'assured': 0.93; 'grey': 0.93; 'hand,': 0.93; 'imagine': 0.93; 'reducing': 0.93; 'room,': 0.93; 'clients,': 0.95; 'connection,': 0.95; 'directly.': 0.95; 'hundred': 0.95 X-TMN: [40Dn8GF8oEaW86FSGJfvNKgdpaNaEhHS] X-Originating-Email: [ramas@live.co.uk] Content-Type: multipart/alternative; boundary="_2983b314-d991-4a3a-affa-83d4803b8da0_" From: Ramas Sami To: "python-list@python.org" Subject: RE: Python-list Digest, Vol 129, Issue 4 Date: Tue, 3 Jun 2014 10:07:49 +0000 Importance: Normal In-Reply-To: References: MIME-Version: 1.0 X-OriginalArrivalTime: 03 Jun 2014 10:07:49.0688 (UTC) FILETIME=[ACC74380:01CF7F13] X-Mailman-Approved-At: Tue, 03 Jun 2014 17:28:28 +0200 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 1827 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1401809310 news.xs4all.nl 2963 [2001:888:2000:d::a6]:41353 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72527 --_2983b314-d991-4a3a-affa-83d4803b8da0_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable My Python 3.3 is shutting down soon I open the new file or existing Python= file Best Regards --Ramas From: python-list-request@python.org Subject: Python-list Digest=2C Vol 129=2C Issue 4 To: python-list@python.org Date: Tue=2C 3 Jun 2014 12:00:05 +0200 Send Python-list mailing list submissions to python-list@python.org =20 To subscribe or unsubscribe via the World Wide Web=2C visit https://mail.python.org/mailman/listinfo/python-list or=2C via email=2C send a message with subject or body 'help' to python-list-request@python.org =20 You can reach the person managing the list at python-list-owner@python.org =20 When replying=2C please edit your Subject line so it is more specific than "Re: Contents of Python-list digest..." --Forwarded Message Attachment-- From: rustompmody@gmail.com To: python-list@python.org Date: Mon=2C 2 Jun 2014 23:28:10 -0700 Subject: Re: can someone explain the concept of "strings (or whatever) bein= g immutable" On Tuesday=2C June 3=2C 2014 10:36:37 AM UTC+5:30=2C Deb Wyatt wrote: > That was just the first question. What does immutable really mean > if you can add items to a list? and concatenate strings? I don't > understand enough to even ask a comprehensible question=2C I guess. =20 It is with some pleasure that I see this question: Most people who are clueless have no clue that they are clueless -- also called the Dunning-Kr=FCger effect. =20 Be assured that this question is much harder and problematic than people be= lieve. =20 There are earlier discussions on this on this list=2C eg =20 https://groups.google.com/forum/#!topic/comp.lang.python/023NLi4XXR4[126-15= 0-false] =20 [Sorry the archive thread is too broken to quote meaningfully] =20 Here's a short(!) summary: Programmer's live in 2 worlds. 1. A timeless mathematical world. Philosophers call this the platonic world after Plato's allegory of the cave: http://en.wikipedia.org/wiki/Allegory_of_the_Cave =20 2. An in-time world that is called "Empirical" in philosophy =20 You cannot reject 2 because your programs run in time and produce effects (hopefully!) in the empirical world. =20 You cannot reject 1 because the time at which you - the programmer - function is in another space-time from the run-time of your program. The very fact that you write a program means you have (been able to) algorithmize out a complex *process* into a simpler recipe - a *program*. =20 Once you see the need for both worldviews 1 and 2 you will see why even the= most deft=3Dfooted trip up doing this dance. eg. When someone says: 3 is immutable but [1=2C2=2C3] is mutable this is not a necessary fact but an incidental choice of python's semantics. =20 Functional languages make everything immutable =20 Assembly language makes everything mutable -- you can self-modify the code containing 3 as an immediate operand in an instruction into one contai= ning something else.=B9 =20 However the basic (necessary not incidental) fact remains - you need to dan= ce between the two worldviews: - platonic and empiric (in traditional philosophy lingo) - declarative and imperative (in computer theory lingo) - FP and OO styles (the two major fashions in programming languages) =20 =20 Choose absolutely only the first and your program can have no effect whatever including writing a result to the screen =20 Choose absolutely only the second that you can have no comprehension of you= r program's semantics. =20 You can find this further elaborated on my blog whose title is a summarizat= ion=20 of what Ive written above: http://blog.languager.org/search/label/FP =20 -------------- =B9Heck! Steven showed some trick to make it happen in python also But Ive not fathomed the black magic! =20 --Forwarded Message Attachment-- From: rustompmody@gmail.com To: python-list@python.org Date: Mon=2C 2 Jun 2014 23:30:28 -0700 Subject: Re: Python 3 is killing Python On Tuesday=2C June 3=2C 2014 11:42:30 AM UTC+5:30=2C jmf wrote: =20 > after thinking no =20 Yes [Also called Oui] =20 --Forwarded Message Attachment-- From: marko@pacujo.net To: python-list@python.org Date: Tue=2C 3 Jun 2014 09:36:51 +0300 Subject: Re: Benefits of asyncio Paul Rubin : =20 > Marko Rauhamaa writes: >> - Thread programming assumes each thread is waiting for precisely >> one external stimulus in any given state -- in practice=2C each >> state must be prepared to handle quite a few possible stimuli. > > Eh? Threads typically have their own event loop dispatching various > kinds of stimuli. =20 I have yet to see that in practice. The "typical" thread works as follows: =20 while True: while request.incomplete(): request.read() # block sql_stmt =3D request.process() db.act(sql_stmt) # block db.commit() # block response =3D request.ok_response() while response.incomplete(): response.write() # block =20 The places marked with the "block" comment are states with only one valid input stimulus. =20 > Have threads communicate by message passing with immutable data in the > messages=2C and things tend to work pretty straightforwardly. =20 Again=2C I have yet to see that in practice. It is more common=2C and naturally enforced=2C with multiprocessing. =20 > Having dealt with some node.js programs and the nest of callbacks they > morph into as the application gets more complicated=2C threads have > their advantages. =20 If threads simplify an asynchronous application=2C that is generally done by oversimplifying and reducing functionality. =20 Yes=2C a "nest of callbacks" can get messy very quickly. That is why you need to be very explicit with your states. Your class needs to have a state field named "state" with clearly named state values. =20 =20 Marko =20 --Forwarded Message Attachment-- From: patil.jay2009@gmail.com To: python-list@python.org Date: Mon=2C 2 Jun 2014 23:40:18 -0700 Subject: Re: Lock Windows Screen GUI using python On Tuesday=2C 3 June 2014 10:39:31 UTC+5:30=2C Ian wrote: > On Mon=2C Jun 2=2C 2014 at 10:28 PM=2C Jaydeep Patil wrote: >=20 > > Dear all=2C >=20 > > Can we Lock Windows Screen GUI till program runs & unlock screen GUI wh= en program finishes? >=20 >=20 >=20 > If you mean can you programmatically bring up the Windows lock screen=2C >=20 > then you can do this: >=20 >=20 >=20 > import ctypes >=20 > ctypes.windll.user32.LockWorkStation() >=20 >=20 >=20 > The only way to unlock it is for the user to log in. >=20 >=20 >=20 > If you mean something else=2C you'll have to be more specific. =20 Hi Lan=2C =20 Currently I am doing some automation in python excel. It read the data & pl= ots number of graphs. It took more than 20 minutes. So while running my pyt= hon program if user clicks on excel=2C error came. =20 So just i want to lock GUI not workstation. =20 I hope you understand this. =20 Let me know if you have any idea about it. =20 =20 Regards Jaydeep Patil =20 --Forwarded Message Attachment-- From: ian.g.kelly@gmail.com To: python-list@python.org Date: Tue=2C 3 Jun 2014 01:09:38 -0600 Subject: Re: Lock Windows Screen GUI using python On Tue=2C Jun 3=2C 2014 at 12:40 AM=2C Jaydeep Patil wrote: > Hi Lan=2C > > Currently I am doing some automation in python excel. It read the data & = plots number of graphs. It took more than 20 minutes. So while running my p= ython program if user clicks on excel=2C error came. > > So just i want to lock GUI not workstation. > > I hope you understand this. > > Let me know if you have any idea about it. =20 You can set the Application.Interactive property on Excel to block user inp= ut: http://msdn.microsoft.com/en-us/library/office/ff841248(v=3Doffice.15).aspx =20 Example: =20 excel_app =3D win32com.client.Dispatch("Excel.Application") excel_app.Interactive =3D False try: # Do some automation... finally: excel_app.Interactive =3D True =20 --Forwarded Message Attachment-- From: steve@pearwood.info To: python-list@python.org Date: Tue=2C 3 Jun 2014 07:46:26 +0000 Subject: Re: can someone explain the concept of "strings (or whatever) bein= g immutable" On Mon=2C 02 Jun 2014 21:06:37 -0800=2C Deb Wyatt wrote: =20 > """a_string =3D "This is a string" > a_string is pointing to the above string >=20 > now I change the value of a_string =20 This is where English can lead us astray. "Change the value of a_string"=20 can mean two different things. An analogy may help make it clear. =20 Some people give their car a name. Suppose I call my car "Vera". I might=20 then "change the value of Vera" by replacing the engine with a more=20 powerful one=2C installing superchargers=2C giving the car a new paint job= =2C=20 and replacing the tape desk with an MP3 player. The name "Vera" still=20 refers to the same physical car=2C but now it is quite different from how=20 it was before. This is equivalent to modifying a mutable value (like a=20 list) in-place. =20 On the other hand=2C I might instead trade in my car for a newer model=2C a= nd=20 transfer the name with it. (I'm very unimaginative when it comes to names=20 -- if I had children=2C they would all be called Chris=2C and all my pets a= re=20 called Fluffy -- even the goldfish.) Whereas before Vera referred to a=20 blue Toyota=2C now it refers to a red Ford. This is equivalent to replacing= =20 the string with a new string. =20 In Python terms=2C we call that "re-binding". "Binding" is another term for= =20 assignment to a name. All of these things are binding operations: =20 import math from random import random x =3D 23 my_string =3D my_string.upper() =20 =20 while these are mutation operations which change the value in-place: =20 my_list[0] =3D 42 my_list.append(None) my_list.sort() some_dict['key'] =3D 'hello world' some_dict.clear() =20 Only mutable objects can be changed in place: e.g. lists=2C dicts=2C sets.= =20 Immutable objects are fixed at creation=2C and cannot be changed: strings= =2C=20 ints=2C floats=2C etc. =20 Some objects fall into a kind of grey area. Tuples are immutable=2C but=20 tuples can include mutable objects inside them=2C and they remain mutable=20 even inside the tuple. =20 t =3D (1=2C 2=2C []) # tuple is fixed t[2] =3D [1] # fails=2C because you're trying to mutate the tuple t[2].append(1) # succeeds=2C because you're mutating the list inside t =20 =20 > a_string =3D "This string is different" I understand that now a_string is > pointing to a different string than it was before=2C in a different > location. >=20 > my question is what happens to the original string?? Is it still in > memory somewhere=2C nameless? """ > That was just the first question. What does immutable really mean if > you can add items to a list? and concatenate strings? I don't > understand enough to even ask a comprehensible question=2C I guess. =20 No=2C it's an excellent question! =20 When an object is *unbound*=2C does it float free in memory? In principle= =2C=20 it could=2C at least for a little while. In practice=2C Python will recogni= se=20 that the string is not being used for anything=2C and reclaim the memory=20 for it. That's called "garbage collection". There are no promises made=20 about when that happens though. It could be instantly=2C or it could be in= =20 an hour. It depends on the specific version and implementation of Python. =20 (CPython=2C the standard version=2C will almost always garbage collect=20 objects nearly instantly. Jython=2C which is Python on the Java Virtual=20 Machine=2C only garbage collects objects every few seconds. So it does=20 vary.) =20 =20 In the case of lists=2C we've seen that a list is mutable=2C so you can=20 append items to lists. In the case of string concatenation=2C strings are=20 immutable=2C so code like this: =20 s =3D "Hello" s +=3D " World!" =20 does not append to the existing string=2C but creates a new string=2C "Hell= o=20 World!"=2C and binds it to the name s. Then the two older strings=2C "Hello= "=20 and " World!" are free to be garbage collected. =20 =20 =20 --=20 Steven =20 --Forwarded Message Attachment-- From: patil.jay2009@gmail.com To: python-list@python.org Date: Tue=2C 3 Jun 2014 00:53:44 -0700 Subject: Re: Lock Windows Screen GUI using python On Tuesday=2C 3 June 2014 12:39:38 UTC+5:30=2C Ian wrote: > On Tue=2C Jun 3=2C 2014 at 12:40 AM=2C Jaydeep Patil wrote: >=20 > > Hi Lan=2C >=20 > > >=20 > > Currently I am doing some automation in python excel. It read the data = & plots number of graphs. It took more than 20 minutes. So while running my= python program if user clicks on excel=2C error came. >=20 > > >=20 > > So just i want to lock GUI not workstation. >=20 > > >=20 > > I hope you understand this. >=20 > > >=20 > > Let me know if you have any idea about it. >=20 >=20 >=20 > You can set the Application.Interactive property on Excel to block user i= nput: >=20 > http://msdn.microsoft.com/en-us/library/office/ff841248(v=3Doffice.15).as= px >=20 >=20 >=20 > Example: >=20 >=20 >=20 > excel_app =3D win32com.client.Dispatch("Excel.Application") >=20 > excel_app.Interactive =3D False >=20 > try: >=20 > # Do some automation... >=20 > finally: >=20 > excel_app.Interactive =3D True =20 =20 Hi Lan=2C =20 Thanks for sharing valuable info. =20 I have another query. =20 We can now block user inputs. But in my automation three is copy & paste wo= rk going on continuously in Excel before plotting the graphs. =20 During copy paste of excel data=2C if user by mistake doing some copy & pas= te operation outside excel(for e.g. doing copy paste in outlook mails=2C fi= refox browser etc)=2C it may be cause for the another error. =20 How i can control this? =20 =20 Thanks & Regards Jaydeep Patil =20 --Forwarded Message Attachment-- From: breamoreboy@yahoo.co.uk To: python-list@python.org Date: Tue=2C 3 Jun 2014 08:59:38 +0100 Subject: Re: can someone explain the concept of "strings (or whatever) bein= g immutable" On 03/06/2014 07:28=2C Rustom Mody wrote: > On Tuesday=2C June 3=2C 2014 10:36:37 AM UTC+5:30=2C Deb Wyatt wrote: >> That was just the first question. What does immutable really mean >> if you can add items to a list? and concatenate strings? I don't >> understand enough to even ask a comprehensible question=2C I guess. > > It is with some pleasure that I see this question: Most people who are > clueless have no clue that they are clueless -- also called the > Dunning-Kr=FCger effect. > > Be assured that this question is much harder and problematic than people = believe. > > There are earlier discussions on this on this list=2C eg > > https://groups.google.com/forum/#!topic/comp.lang.python/023NLi4XXR4[126-= 150-false] > > [Sorry the archive thread is too broken to quote meaningfully] > =20 This list is available in maybe six different places=2C so I had to=20 chuckle that you picked just about the worst possible to reference :) =20 --=20 My fellow Pythonistas=2C ask not what our language can do for you=2C ask=20 what you can do for our language. =20 Mark Lawrence =20 --- This email is free from viruses and malware because avast! Antivirus protec= tion is active. http://www.avast.com =20 =20 =20 --Forwarded Message Attachment-- From: __peter__@web.de To: python-list@python.org Date: Tue=2C 3 Jun 2014 10:01:26 +0200 Subject: Re: Strange Behavior Steven D'Aprano wrote: =20 > On Mon=2C 02 Jun 2014 20:05:29 +0200=2C robertw89 wrote: >=20 >> I invoked the wrong bug.py :/ =2C works fine now (this happens to me whe= n >> im a bit tired sometimes...). >=20 > Clarity in naming is an excellent thing. If you have two files called > "bug.py"=2C that's two too many. =20 In the case of the OP the code is likely to be thrown away once the bug is= =20 found. Putting all experiments into a single folder even with the overly=20 generic name "bug" would have been "good enough" to avoid the problem. =20 > Imagine having fifty files called "program.py". Which one is which? How > do you know? Programs should be named by what they do (think of Word=2C > which does word processing=2C or Photoshop=2C which does photo editing)= =2C or > when that isn't practical=2C at least give them a unique and memorable na= me > (Outlook=2C Excel). The same applies to files demonstrating bugs. =20 Outlook and Excel are only good names because these are popular=20 applications. If I were to name some private scripts in that style and not= =20 use them for a few months -- I don't think I'd have a clue what excel.py is= =20 meant to do.=20 =20 I have a few find_dupes dedupe_xxx compare_xxx scripts lying around and no= =20 idea which is which. So a reasonably clear name is not sufficient if there= =20 are other scripts that perform similar tasks. =20 One approach that seems to be working so far is to combine several scripts= =20 into one using argparse subparsers. This results in more frequent usage=20 which means I can get away with short meaningless names=2C and infrequent=20 actions are just one =20 $ xx -h =20 away. =20 =20 --Forwarded Message Attachment-- From: breamoreboy@yahoo.co.uk To: python-list@python.org Date: Tue=2C 3 Jun 2014 09:03:12 +0100 Subject: Re: Python 3 is killing Python On 03/06/2014 07:30=2C Rustom Mody wrote: > On Tuesday=2C June 3=2C 2014 11:42:30 AM UTC+5:30=2C jmf wrote: > >> after thinking no > > Yes [Also called Oui] > =20 I'm very puzzled over "thinking"=2C what context was this in as I've=20 kill-filed our most illustrious resident unicode expert? =20 --=20 My fellow Pythonistas=2C ask not what our language can do for you=2C ask=20 what you can do for our language. =20 Mark Lawrence =20 --- This email is free from viruses and malware because avast! Antivirus protec= tion is active. http://www.avast.com =20 =20 =20 --Forwarded Message Attachment-- From: breamoreboy@yahoo.co.uk To: python-list@python.org Date: Tue=2C 3 Jun 2014 09:05:55 +0100 Subject: Re: Lock Windows Screen GUI using python On 03/06/2014 08:53=2C Jaydeep Patil wrote: =20 Would you please use the mailing list=20 https://mail.python.org/mailman/listinfo/python-list or read and action=20 this https://wiki.python.org/moin/GoogleGroupsPython to prevent us=20 seeing double line spacing and single line paragraphs=2C thanks. =20 --=20 My fellow Pythonistas=2C ask not what our language can do for you=2C ask=20 what you can do for our language. =20 Mark Lawrence =20 --- This email is free from viruses and malware because avast! Antivirus protec= tion is active. http://www.avast.com =20 =20 =20 --Forwarded Message Attachment-- From: pmiscml@gmail.com CC: python-list@python.org To: tjreedy@udel.edu Date: Tue=2C 3 Jun 2014 11:31:14 +0300 Subject: Re: Benefits of asyncio Hello=2C =20 On Mon=2C 02 Jun 2014 21:51:35 -0400 Terry Reedy wrote: =20 > To all the great responders. If anyone thinks the async intro is=20 > inadequate and has a paragraph to contribute=2C open a tracker issue. =20 Not sure about intro (where's that?)=2C but docs (https://docs.python.org/3/library/asyncio.html) are pretty confusing and bugs are reported=2C with no response: http://bugs.python.org/issue21365 =20 >=20 > --=20 > Terry Jan Reedy =20 --=20 Best regards=2C Paul mailto:pmiscml@gmail.com =20 --Forwarded Message Attachment-- From: DMusiige@sennheisercommunications.com To: python-list@python.org Date: Tue=2C 3 Jun 2014 08:10:03 +0000 Subject: Automating windows media player on win7 =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= Hi guys=2C=0A= =0A= I have been fighting with automating wmplayer but with no success.=0A= It looks to me that using the .OCX would be the best option. I found the co= de below on the net but I cannot get it to work.=0A= I can see from device manager that a driver is started by I get no audio ou= t.=0A= =0A= What am I doing wrong guys? =0A= =0A= =0A= # this program will play MP3=2C WMA=2C MID=2C WAV files via the WindowsMedi= aPlayer=0A= from win32com.client import Dispatch=0A= mp =3D Dispatch("WMPlayer.OCX")=0A= tune =3D mp.newMedia("./plays.wav")=0A= mp.currentPlaylist.appendItem(tune)=0A= mp.controls.play()=0A= raw_input("Press Enter to stop playing")=0A= =0A= mp.controls.stop()=0A= =0A= Br=0A= Deo=0A= =0A= =0A= =0A= --Forwarded Message Attachment-- From: rosuav@gmail.com CC: python-list@python.org Date: Tue=2C 3 Jun 2014 18:47:11 +1000 Subject: Re: Benefits of asyncio On Tue=2C Jun 3=2C 2014 at 4:36 PM=2C Marko Rauhamaa wro= te: > I have yet to see that in practice. The "typical" thread works as > follows: > > while True: > while request.incomplete(): > request.read() # block > sql_stmt =3D request.process() > db.act(sql_stmt) # block > db.commit() # block > response =3D request.ok_response() > while response.incomplete(): > response.write() # block > > The places marked with the "block" comment are states with only one > valid input stimulus. > ... > Yes=2C a "nest of callbacks" can get messy very quickly. That is why you > need to be very explicit with your states. Your class needs to have a > state field named "state" with clearly named state values. =20 Simple/naive way to translate this into a callback system is like this: =20 def request_read_callback(request=2C data): request.read(data) # however that part works if not request.incomplete(): request.process() =20 def write(request=2C data): request.write_buffer +=3D data request.attempt_write() # sets up callbacks for async writing =20 def request.process(self): # I know this isn't valid syntax db.act(whatever) # may block but shouldn't for long db.commit() # ditto write(self=2C response) # won't block =20 =20 This works as long as your database is reasonably fast and close (common case for a lot of web servers: DB runs on same computer as web and application and etc servers). It's nice and simple=2C lets you use a single database connection (although you should probably wrap it in a try/finally to ensure that you roll back on any exception)=2C and won't materially damage throughput as long as you don't run into problems. For a database driven web site=2C most of the I/O time will be waiting for clients=2C not waiting for your database. =20 Getting rid of those blocking database calls means having multiple concurrent transactions on the database. Whether you go async or threaded=2C this is going to happen. Unless your database lets you run multiple simultaneous transactions on a single connection (I don't think the Python DB API allows that=2C and I can't think of any DB backends that support it=2C off hand)=2C that means that every single concurrency point needs its own database connection. With threads=2C you could have a pool of (say) a dozen or so=2C one per thread=2C with each one working synchronously=3B with asyncio=2C you'd have to have one for every single incoming client request=2C or else faff around with semaphores and resource pools and such manually. The throughput you gain by making those asynchronous with callbacks is quite probably destroyed by the throughput you lose in having too many simultaneous connections to the database. I can't prove that=2C obviously=2C but I do know that PostgreSQL requires up-front RAM allocation based on the max_connections setting=2C and trying to support 5000 connections started to get kinda stupid. =20 So how do you deal with the possibility that the database will block? "Pure" threading (one thread listens for clients=2C spin off a thread for each client=2C end the thread when the client disconnects) copes poorly=3B async I/O copes poorly. The thread pool copes well (you know exactly how many connections you'll need - one per thread in the pool)=2C but doesn't necessarily solve the problem (you can get all threads waiting on the database and none handling other requests). Frankly=2C I think the only solution is to beef up the database so it won't block for too long (and=2C duh=2C to solve any stupid locking problems=2C because they WILL kill you :) ). =20 > If threads simplify an asynchronous application=2C that is generally done > by oversimplifying and reducing functionality. =20 Which means that I disagree with this statement. In my opinion=2C both simple models (pure threading and asyncio) can express the same functionality=3B the hybrid thread-pool model may simplify things a bit in the interests of resource usage=3B but threading does let you think about code the same way for one client as for fifty=2C without any change of functionality. Compare: =20 # Console I/O: def print_menu(): print("1: Spam") print("2: Ham") print("3: Quit") =20 def spam(): print("Spam=2C spam=2C spam=2C spam=2C") while input("Continue? ")!=3D"NO!": print("spam=2C spam=2C spam...") =20 def mainloop(): print("Welcome!") while True: print_menu() x =3D int(input("What would you like? ")) if x =3D=3D 1: spam() elif x =3D=3D 2: ham() elif x =3D=3D 3: break else: print("I don't know numbers like %d."%x) print("Goodbye!") =20 =20 I could translate this into a pure-threading system very easily: =20 # Socket I/O: import consoleio class TerminateRequest(Exception): pass tls =3D threading.local() def print(s): tls.socket.write(s+"\r\n") # Don't forget=2C most of the internet uses = \r\n! =20 def input(prompt): tls.socket.write(s) while '\n' not in tls.readbuffer: tls.readbuffer +=3D tls.socket.read() if not tls.socket.connected(): raise TerminateRequest ret=2C _=2C tls.readbuffer =3D tls.readbuffer.partition("\n") return ret.strip("\r") =20 consoleio.print =3D print consoleio.input =3D input =20 def thread(sock): tls.socket =3D sock tls.readbuffer =3D "" try: consoleio.mainloop() except TerminateRequest: pass =20 mainsock =3D socket.socket() # bind to port=2C whatever mainsock.listen(5) while True: threading.Thread(target=3Dthread=2Cargs=3D(mainsock.accept()=2C)) =20 =20 The only changes I made to the application main loop are to change (via injection) print and input to use the socket. Everything else - the (bad) logic inside spam()=2C helper functions=2C etc=2C etc - works exactly the same way. So if you're coming from a single-thread single-client starting point=2C it's definitely way simpler to follow a model like this. (And I have written enough programs along this sort of line to be able to write the above without more than some quick checks to see how thread-local storage is done in Python. It's a really simple model. On the flip side=2C that does also mean the code above is completely untested=2C not to mention stubby in places=2C so it probably won't actually run.) =20 How do you translate that to asynchronous I/O? Normally=2C with piles and piles of callbacks. I haven't looked into tulip yet=2C but my understanding is that it may be possible to tulipify the above code in the same way that I socketified it - you'd simply have a "yield from" inside input()=2C which would let the system go and deal with other requests=3B but otherwise=2C you would need to completely rewrite the main code. The exact same functionality would look a lot messier=3B and you have the exact same problems to deal with either way. Your connection state has to cope with both input and output buffers (since you have to make sure you don't block inside print() either)=2C and while you can in most applications assume that there won't be a huge amount of output buffering (and can therefore let mainloop() pretend that it all got written instantly=2C while the actual writing happens in the background)=2C sometimes you have to be explicit about that part of state too. So the consoleio module above would need a lot of separate states: every single print() or input() call becomes its own state=2C in which the connection might stall. Do you really want to do that with callbacks? Because it would *definitely* be less clear. =20 ChrisA =20 --Forwarded Message Attachment-- From: rosuav@gmail.com CC: python-list@python.org Date: Tue=2C 3 Jun 2014 18:57:35 +1000 Subject: Re: Automating windows media player on win7 On Tue=2C Jun 3=2C 2014 at 6:10 PM=2C Deogratius Musiige wrote: > Hi guys=2C > > > > I have been fighting with automating wmplayer but with no success. > > It looks to me that using the .OCX would be the best option. I found the > code below on the net but I cannot get it to work. > > I can see from device manager that a driver is started by I get no audio > out. > > What am I doing wrong guys? > > > > # this program will play MP3=2C WMA=2C MID=2C WAV files via the WindowsMe= diaPlayer > > from win32com.client import Dispatch > > mp =3D Dispatch("WMPlayer.OCX") > > tune =3D mp.newMedia("./plays.wav") > > mp.currentPlaylist.appendItem(tune) > > mp.controls.play() > > raw_input("Press Enter to stop playing") > > mp.controls.stop() > > > > Br > > Deo =20 First suggestion: post plain text to this list=2C not HTML. You don't need it to look like the above. :) =20 Secondly: Is there a particular reason that you need to be automating Windows Media Player specifically? I have a similar project which works by sending keystrokes=2C which means it works with anything that reacts to keys=3B mainly=2C I use it with VLC. It can invoke a movie or audio file=2C can terminate the process=2C and can send a variety of commands via keys. It's designed to be used on a (trusted) LAN. =20 Code is here: https://github.com/Rosuav/Yosemite =20 Once something's invoked by the Yosemite project=2C it simply runs as normal inside VLC. Easy to debug audio problems=2C because they're managed the exact same way. Granted=2C this does assume that it's given full control of the screen (it's designed to manage full-screen video playback=3B in fact=2C my siblings are right now watching Toy Story 3 in the other room=2C using an old laptop driving a TV via S-Video=2C all managed via the above project)=2C so it may not be ideal for background music on a computer you use for other things=3B but feel free to borrow ideas and/or code from there. (And for what it's worth=2C I use this as one of my sources of BGM when I'm coding - just let it invoke the file=2C then manually flip focus back to what I'm doing.) =20 ChrisA =20 --Forwarded Message Attachment-- From: rosuav@gmail.com CC: python-list@python.org Date: Tue=2C 3 Jun 2014 19:11:02 +1000 Subject: Re: Lock Windows Screen GUI using python On Tue=2C Jun 3=2C 2014 at 5:53 PM=2C Jaydeep Patil wrote: > > During copy paste of excel data=2C if user by mistake doing some copy & p= aste operation outside excel(for e.g. doing copy paste in outlook mails=2C = firefox browser etc)=2C it may be cause for the another error. > > How i can control this? =20 Suggestion: Don't. If you really need this level of control of the workstation=2C you are going about things wrongly. This is a recipe for fragility and horrific usability problems. There are two simple solutions: =20 1) Make it really obvious that you're controlling the computer=2C by putting something big across the screen - a splash screen=2C of sorts - which is set to Always On Top and gives a message. And then just trust that the user won't do anything=2C because you've done everything reasonable. No further control needed. =20 2) Automate your code by moving stuff around on the disk=2C *not* by actually working through Excel. Twenty minutes of Excel automation should probably become a proper application that reads in some data and generates some graphs. And it'd probably be faster=2C too (even if Excel's performance is stellar=2C which I very much doubt=2C it's always slower to work through a GUI than to do the work directly). Figure out what you're really trying to do=2C and do that directly. =20 Also=2C please follow Mark's advice. =20 ChrisA =20 --Forwarded Message Attachment-- From: marko@pacujo.net To: python-list@python.org Date: Tue=2C 3 Jun 2014 12:10:12 +0300 Subject: Re: Benefits of asyncio Chris Angelico : =20 > def request.process(self): # I know this isn't valid syntax > db.act(whatever) # may block but shouldn't for long > db.commit() # ditto > write(self=2C response) # won't block > > This works as long as your database is reasonably fast and close =20 I find that assumption unacceptable. =20 The DB APIs desperately need asynchronous variants. As it stands=2C you are forced to delegate your DB access to threads/processes. =20 > So how do you deal with the possibility that the database will block? =20 You separate the request and response parts of the DB methods. That's how it is implemented internally anyway. =20 Say no to blocking APIs. =20 > but otherwise=2C you would need to completely rewrite the main code. =20 That's a good reason to avoid threads. Once you realize you would have been better off with an async approach=2C you'll have to start over. You can easily turn a nonblocking solution into a blocking one but not the other way around. =20 =20 Marko =20 --Forwarded Message Attachment-- From: rosuav@gmail.com CC: python-list@python.org Date: Tue=2C 3 Jun 2014 19:30:14 +1000 Subject: Re: Benefits of asyncio On Tue=2C Jun 3=2C 2014 at 7:10 PM=2C Marko Rauhamaa wro= te: > Chris Angelico : > >> def request.process(self): # I know this isn't valid syntax >> db.act(whatever) # may block but shouldn't for long >> db.commit() # ditto >> write(self=2C response) # won't block >> >> This works as long as your database is reasonably fast and close > > I find that assumption unacceptable. =20 It is a dangerous assumption. =20 > The DB APIs desperately need asynchronous variants. As it stands=2C you > are forced to delegate your DB access to threads/processes. > >> So how do you deal with the possibility that the database will block? > > You separate the request and response parts of the DB methods. That's > how it is implemented internally anyway. > > Say no to blocking APIs. =20 Okay=2C but how do you handle two simultaneous requests going through the processing that you see above? You *MUST* separate them onto two transactions=2C otherwise one will commit half of the other's work. (Or are you forgetting Databasing 101 - a transaction should be a logical unit of work?) And since you can't=2C with most databases=2C have two transactions on one connection=2C that means you need a separate connection for each request. Given that the advantages of asyncio include the ability to scale to arbitrary numbers of connections=2C it's not really a good idea to then say "oh but you need that many concurrent database connections". Most systems can probably handle a few thousand threads without a problem=2C but a few million is going to cause major issues=3B but most databases start getting inefficient at a few thousand concurrent sessions. =20 >> but otherwise=2C you would need to completely rewrite the main code. > > That's a good reason to avoid threads. Once you realize you would have > been better off with an async approach=2C you'll have to start over. You > can easily turn a nonblocking solution into a blocking one but not the > other way around. =20 Alright. I'm throwing down the gauntlet. Write me a purely nonblocking web site concept that can handle a million concurrent connections=2C where each one requires one query against the database=2C and one in a hundred of them require five queries which happen atomically. I can do it with a thread pool and blocking database queries=2C and by matching the thread pool size and the database concurrent connection limit=2C I can manage memory usage fairly easily=3B how do you do it efficiently with pure async I/O? =20 ChrisA =20 --Forwarded Message Attachment-- From: rosuav@gmail.com CC: python-list@python.org Date: Tue=2C 3 Jun 2014 19:46:27 +1000 Subject: Re: Automating windows media player on win7 On Tue=2C Jun 3=2C 2014 at 7:42 PM=2C Deogratius Musiige wrote: > Hi Chris=2C > > I want to have wmplayer as part of my automitized test for a headset via = the > USB HID. > > I want to be able to execute some of the following operations in my pytho= n > script: > > 1. Play > > 2. Get playing track > > 3. Next > > 4. Get active device > > 5. =85 > > I am not sure if you are able to do this with your project =20 Play=2C definitely. Next=2C not specifically=2C but by sending the letter 'n' you can achieve that. Active device? Not sure what you mean there. =20 The one part that doesn't exist is "Get playing track". But you could manage this the other way around=2C by not invoking a playlist at all. If you run "vlc --play-and-exit some_file.wav"=2C then when that process terminates=2C the track has finished. Kill the process or send Ctrl-Q to skip to the next track. Keep track (pun intended) of what file you've most recently invoked. =20 I'm not sure how this ties in with your headset testing=2C though. =20 By the look of things=2C the Yosemite project isn't a "here it is=2C just deploy it" solution=2C but you may find that there's some useful code you can borrow. =20 ChrisA =20 = --_2983b314-d991-4a3a-affa-83d4803b8da0_ Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable
My Python 3.3  =3Bis shutting down soon I open the new fil= e or existing Python file

Best Regards<= /font>

--= Ramas



From: python-list-request@pyt= hon.org
Subject: Python-list Digest=2C Vol 129=2C Issue 4
To: python-= list@python.org
Date: Tue=2C 3 Jun 2014 12:00:05 +0200

Send =
Python-list mailing list submissions to
python-list@python.org

= To subscribe or unsubscribe via the World Wide Web=2C visit
htt= ps://mail.python.org/mailman/listinfo/python-list
or=2C via email=2C= send a message with subject or body 'help' to
python-list-request@pyth= on.org

You can reach the person managing the list at
python-lis= t-owner@python.org

When replying=2C please edit your Subject line s= o it is more specific
than "Re: Contents of Python-list digest..."


--Forwarded Message Attachment--
From: rustompmody@gmail.com=
To: python-list@python.org
Date: Mon=2C 2 Jun 2014 23:28:10 -0700Subject: Re: can someone explain the concept of "strings (or whatever) bei= ng immutable"

On Tuesday=2C June 3=2C 2014 10:36:37 AM UTC+5:30=
=2C Deb Wyatt wrote:
>=3B That was just the first question. What does= immutable really mean
>=3B if you can add items to a list? and concat= enate strings? I don't
>=3B understand enough to even ask a comprehen= sible question=2C I guess.

It is with some pleasure that I see this= question: Most people who are
clueless have no clue that they are cluel= ess -- also called the
Dunning-Kr=FCger effect.

Be assured that = this question is much harder and problematic than people believe.

T= here are earlier discussions on this on this list=2C eg

https://groups.google.com/forum/#!topic/comp.lang.python/023= NLi4XXR4[126-150-false]

[Sorry the archive thread is too broken= to quote meaningfully]

Here's a short(!) summary:
Programmer's = live in 2 worlds.
1. A timeless mathematical world. Philosophers call th= is the platonic world
after Plato's allegory of the cave:
http:/= /en.wikipedia.org/wiki/Allegory_of_the_Cave

2. An in-time world= that is called "Empirical" in philosophy

You cannot reject 2 becau= se your programs run in time and produce
effects (hopefully!) in the emp= irical world.

You cannot reject 1 because the time at which you - t= he programmer -
function is in another space-time from the run-time of y= our program.
The very fact that you write a program means you have (been= able to)
algorithmize out a complex *process* into a simpler recipe - a= *program*.

Once you see the need for both worldviews 1 and 2 you w= ill see why even the most
deft=3Dfooted trip up doing this dance. eg. Wh= en someone says:
3 is immutable but [1=2C2=2C3] is mutable this is not a= necessary fact but
an incidental choice of python's semantics.

= Functional languages make everything immutable

Assembly language ma= kes everything mutable -- you can self-modify the
code containing 3 as a= n immediate operand in an instruction into one containing
something else= .=B9

However the basic (necessary not incidental) fact remains - yo= u need to dance between
the two worldviews:
- platonic and empiric (i= n traditional philosophy lingo)
- declarative and imperative (in compute= r theory lingo)
- FP and OO styles (the two major fashions in programmin= g languages)


Choose absolutely only the first and your program= can have no effect
whatever including writing a result to the screen
Choose absolutely only the second that you can have no comprehension = of your
program's semantics.

You can find this further elaborate= d on my blog whose title is a summarization
of what Ive written above: = ht= tp://blog.languager.org/search/label/FP

--------------
=B9He= ck! Steven showed some trick to make it happen in python also
But Ive no= t fathomed the black magic!



--Forwarded Message Attac= hment--
From: rustompmody@gmail.com
To: python-list@python.org
Dat= e: Mon=2C 2 Jun 2014 23:30:28 -0700
Subject: Re: Python 3 is killing Pyt= hon

On Tuesday=2C June 3=2C 2014 11:42:30 AM UTC+5:30=2C jmf wr=
ote:

>=3B after thinking no

Yes [Also called Oui]


--Forwarded Message Attachment--
From: marko@pacujo.netTo: python-list@python.org
Date: Tue=2C 3 Jun 2014 09:36:51 +0300
S= ubject: Re: Benefits of asyncio

Paul Rubin <=3Bno.email@nospa=
m.invalid>=3B:

>=3B Marko Rauhamaa <=3Bmarko@pacujo.net>=3B= writes:
>=3B>=3B - Thread programming assumes each thread is wa= iting for precisely
>=3B>=3B one external stimulus in any give= n state -- in practice=2C each
>=3B>=3B state must be prepared= to handle quite a few possible stimuli.
>=3B
>=3B Eh? Threads t= ypically have their own event loop dispatching various
>=3B kinds of s= timuli.

I have yet to see that in practice. The "typical" thread wo= rks as
follows:

while True:
while request.incompl= ete():
request.read() # block
sql= _stmt =3D request.process()
db.act(sql_stmt) #= block
db.commit() # block
res= ponse =3D request.ok_response()
while response.incomplete():
= response.write() # block

The places marke= d with the "block" comment are states with only one
valid input stimulus= .

>=3B Have threads communicate by message passing with immutable= data in the
>=3B messages=2C and things tend to work pretty straightf= orwardly.

Again=2C I have yet to see that in practice. It is more c= ommon=2C and
naturally enforced=2C with multiprocessing.

>=3B = Having dealt with some node.js programs and the nest of callbacks they
&= gt=3B morph into as the application gets more complicated=2C threads have>=3B their advantages.

If threads simplify an asynchronous appl= ication=2C that is generally done
by oversimplifying and reducing functi= onality.

Yes=2C a "nest of callbacks" can get messy very quickly. T= hat is why you
need to be very explicit with your states. Your class nee= ds to have a
state field named "state" with clearly named state values.<= br>

Marko



--Forwarded Message Attachment--From: patil.jay2009@gmail.com
To: python-list@python.org
Date: Mon= =2C 2 Jun 2014 23:40:18 -0700
Subject: Re: Lock Windows Screen GUI using= python

On Tuesday=2C 3 June 2014 10:39:31 UTC+5:30=2C Ian  wro=
te:
>=3B On Mon=2C Jun 2=2C 2014 at 10:28 PM=2C Jaydeep Patil <=3Bpa= til.jay2009@gmail.com>=3B wrote:
>=3B
>=3B >=3B Dear all=2C<= br>>=3B
>=3B >=3B Can we Lock Windows Screen GUI till program run= s &=3B unlock screen GUI when program finishes?
>=3B
>=3B >=3B
>=3B If you mean can you programmatically bring up the Window= s lock screen=2C
>=3B
>=3B then you can do this:
>=3B
&= gt=3B
>=3B
>=3B import ctypes
>=3B
>=3B ctypes.windl= l.user32.LockWorkStation()
>=3B
>=3B
>=3B
>=3B The o= nly way to unlock it is for the user to log in.
>=3B
>=3B
&g= t=3B
>=3B If you mean something else=2C you'll have to be more specif= ic.

Hi Lan=2C

Currently I am doing some automation in pytho= n excel. It read the data &=3B plots number of graphs. It took more than= 20 minutes. So while running my python program if user clicks on excel=2C = error came.

So just i want to lock GUI not workstation.

I h= ope you understand this.

Let me know if you have any idea about it.=


Regards
Jaydeep Patil



--Forwarded Me= ssage Attachment--
From: ian.g.kelly@gmail.com
To: python-list@python= .org
Date: Tue=2C 3 Jun 2014 01:09:38 -0600
Subject: Re: Lock Windows= Screen GUI using python

On Tue=2C Jun 3=2C 2014 at 12:40 AM=2C=
 Jaydeep Patil <=3Bpatil.jay2009@gmail.com>=3B wrote:
>=3B Hi Lan= =2C
>=3B
>=3B Currently I am doing some automation in python exce= l. It read the data &=3B plots number of graphs. It took more than 20 mi= nutes. So while running my python program if user clicks on excel=2C error = came.
>=3B
>=3B So just i want to lock GUI not workstation.
&g= t=3B
>=3B I hope you understand this.
>=3B
>=3B Let me know = if you have any idea about it.

You can set the Application.Interact= ive property on Excel to block user input:
http://msdn.micros= oft.com/en-us/library/office/ff841248(v=3Doffice.15).aspx

Examp= le:

excel_app =3D win32com.client.Dispatch("Excel.Application")
= excel_app.Interactive =3D False
try:
# Do some automation...
f= inally:
excel_app.Interactive =3D True



--Forwa= rded Message Attachment--
From: steve@pearwood.info
To: python-list@p= ython.org
Date: Tue=2C 3 Jun 2014 07:46:26 +0000
Subject: Re: can som= eone explain the concept of "strings (or whatever) being immutable"

=
On Mon=2C 02 Jun 2014 21:06:37 -0800=2C Deb Wyatt wrote:

>= =3B """a_string =3D "This is a string"
>=3B a_string is pointing to th= e above string
>=3B
>=3B now I change the value of a_string
=
This is where English can lead us astray. "Change the value of a_string= "
can mean two different things. An analogy may help make it clear.
=
Some people give their car a name. Suppose I call my car "Vera". I mig= ht
then "change the value of Vera" by replacing the engine with a more =
powerful one=2C installing superchargers=2C giving the car a new paint = job=2C
and replacing the tape desk with an MP3 player. The name "Vera" = still
refers to the same physical car=2C but now it is quite different = from how
it was before. This is equivalent to modifying a mutable value= (like a
list) in-place.

On the other hand=2C I might instead t= rade in my car for a newer model=2C and
transfer the name with it. (I'm= very unimaginative when it comes to names
-- if I had children=2C they= would all be called Chris=2C and all my pets are
called Fluffy -- even= the goldfish.) Whereas before Vera referred to a
blue Toyota=2C now it= refers to a red Ford. This is equivalent to replacing
the string with = a new string.

In Python terms=2C we call that "re-binding". "Bindin= g" is another term for
assignment to a name. All of these things are bi= nding operations:

import math
from random import random
x =3D= 23
my_string =3D my_string.upper()


while these are mutatio= n operations which change the value in-place:

my_list[0] =3D 42
= my_list.append(None)
my_list.sort()
some_dict['key'] =3D 'hello world= '
some_dict.clear()

Only mutable objects can be changed in place= : e.g. lists=2C dicts=2C sets.
Immutable objects are fixed at creation= =2C and cannot be changed: strings=2C
ints=2C floats=2C etc.

So= me objects fall into a kind of grey area. Tuples are immutable=2C but
t= uples can include mutable objects inside them=2C and they remain mutable even inside the tuple.

t =3D (1=2C 2=2C []) # tuple is fixed
= t[2] =3D [1] # fails=2C because you're trying to mutate the tuple
t[2].= append(1) # succeeds=2C because you're mutating the list inside t

=
>=3B a_string =3D "This string is different" I understand that now a= _string is
>=3B pointing to a different string than it was before=2C i= n a different
>=3B location.
>=3B
>=3B my question is what = happens to the original string?? Is it still in
>=3B memory somewhere= =2C nameless? """
>=3B That was just the first question. What does im= mutable really mean if
>=3B you can add items to a list? and concatena= te strings? I don't
>=3B understand enough to even ask a comprehensib= le question=2C I guess.

No=2C it's an excellent question!

W= hen an object is *unbound*=2C does it float free in memory? In principle=2C=
it could=2C at least for a little while. In practice=2C Python will re= cognise
that the string is not being used for anything=2C and reclaim t= he memory
for it. That's called "garbage collection". There are no prom= ises made
about when that happens though. It could be instantly=2C or i= t could be in
an hour. It depends on the specific version and implement= ation of Python.

(CPython=2C the standard version=2C will almost al= ways garbage collect
objects nearly instantly. Jython=2C which is Pytho= n on the Java Virtual
Machine=2C only garbage collects objects every fe= w seconds. So it does
vary.)


In the case of lists=2C we've= seen that a list is mutable=2C so you can
append items to lists. In th= e case of string concatenation=2C strings are
immutable=2C so code like= this:

s =3D "Hello"
s +=3D " World!"

does not append to= the existing string=2C but creates a new string=2C "Hello
World!"=2C a= nd binds it to the name s. Then the two older strings=2C "Hello"
and " = World!" are free to be garbage collected.



--
Steven


--Forwarded Message Attachment--
From: patil.jay200= 9@gmail.com
To: python-list@python.org
Date: Tue=2C 3 Jun 2014 00:53:= 44 -0700
Subject: Re: Lock Windows Screen GUI using python

O=
n Tuesday=2C 3 June 2014 12:39:38 UTC+5:30=2C Ian  wrote:
>=3B On Tue= =2C Jun 3=2C 2014 at 12:40 AM=2C Jaydeep Patil <=3Bpatil.jay2009@gmail.co= m>=3B wrote:
>=3B
>=3B >=3B Hi Lan=2C
>=3B
>=3B &= gt=3B
>=3B
>=3B >=3B Currently I am doing some automation in p= ython excel. It read the data &=3B plots number of graphs. It took more = than 20 minutes. So while running my python program if user clicks on excel= =2C error came.
>=3B
>=3B >=3B
>=3B
>=3B >=3B So = just i want to lock GUI not workstation.
>=3B
>=3B >=3B
>= =3B
>=3B >=3B I hope you understand this.
>=3B
>=3B >= =3B
>=3B
>=3B >=3B Let me know if you have any idea about it.<= br>>=3B
>=3B
>=3B
>=3B You can set the Application.Inte= ractive property on Excel to block user input:
>=3B
>=3B http://msdn.microsoft.com/en-us/library/office/ff841248(v=3Doffice.= 15).aspx
>=3B
>=3B
>=3B
>=3B Example:
>=3B
= >=3B
>=3B
>=3B excel_app =3D win32com.client.Dispatch("Excel.= Application")
>=3B
>=3B excel_app.Interactive =3D False
>= =3B
>=3B try:
>=3B
>=3B # Do some automation...
>= =3B
>=3B finally:
>=3B
>=3B excel_app.Interactive =3D = True


Hi Lan=2C

Thanks for sharing valuable info.
<= br>I have another query.

We can now block user inputs. But in my au= tomation three is copy &=3B paste work going on continuously in Excel be= fore plotting the graphs.

During copy paste of excel data=2C if use= r by mistake doing some copy &=3B paste operation outside excel(for e.g.= doing copy paste in outlook mails=2C firefox browser etc)=2C it may be cau= se for the another error.

How i can control this?


Than= ks &=3B Regards
Jaydeep Patil



--Forwarded Messa= ge Attachment--
From: breamoreboy@yahoo.co.uk
To: python-list@python.= org
Date: Tue=2C 3 Jun 2014 08:59:38 +0100
Subject: Re: can someone e= xplain the concept of "strings (or whatever) being immutable"

O=
n 03/06/2014 07:28=2C Rustom Mody wrote:
>=3B On Tuesday=2C June 3=2C = 2014 10:36:37 AM UTC+5:30=2C Deb Wyatt wrote:
>=3B>=3B That was just= the first question. What does immutable really mean
>=3B>=3B if yo= u can add items to a list? and concatenate strings? I don't
>=3B>= =3B understand enough to even ask a comprehensible question=2C I guess.
= >=3B
>=3B It is with some pleasure that I see this question: Most pe= ople who are
>=3B clueless have no clue that they are clueless -- also= called the
>=3B Dunning-Kr=FCger effect.
>=3B
>=3B Be assur= ed that this question is much harder and problematic than people believe.>=3B
>=3B There are earlier discussions on this on this list=2C eg=
>=3B
>=3B https://groups.google.com/fo= rum/#!topic/comp.lang.python/023NLi4XXR4[126-150-false]
>=3B
&g= t=3B [Sorry the archive thread is too broken to quote meaningfully]
>= =3B

This list is available in maybe six different places=2C so I ha= d to
chuckle that you picked just about the worst possible to reference= :)

--
My fellow Pythonistas=2C ask not what our language can d= o for you=2C ask
what you can do for our language.

Mark Lawrenc= e

---
This email is free from viruses and malware because avast!= Antivirus protection is active.
http://www.avast.com





--Forw= arded Message Attachment--
From: __peter__@web.de
To: python-list@pyt= hon.org
Date: Tue=2C 3 Jun 2014 10:01:26 +0200
Subject: Re: Strange B= ehavior

Steven D'Aprano wrote:

>=3B On Mon=2C 02 Jun = 2014 20:05:29 +0200=2C robertw89 wrote:
>=3B
>=3B>=3B I invoke= d the wrong bug.py :/ =2C works fine now (this happens to me when
>=3B= >=3B im a bit tired sometimes...).
>=3B
>=3B Clarity in naming= is an excellent thing. If you have two files called
>=3B "bug.py"=2C = that's two too many.

In the case of the OP the code is likely to be= thrown away once the bug is
found. Putting all experiments into a sing= le folder even with the overly
generic name "bug" would have been "good= enough" to avoid the problem.

>=3B Imagine having fifty files ca= lled "program.py". Which one is which? How
>=3B do you know? Programs = should be named by what they do (think of Word=2C
>=3B which does word= processing=2C or Photoshop=2C which does photo editing)=2C or
>=3B wh= en that isn't practical=2C at least give them a unique and memorable name>=3B (Outlook=2C Excel). The same applies to files demonstrating bugs.<= br>
Outlook and Excel are only good names because these are popular applications. If I were to name some private scripts in that style and not=
use them for a few months -- I don't think I'd have a clue what excel.= py is
meant to do.

I have a few find_dupes dedupe_xxx compare_= xxx scripts lying around and no
idea which is which. So a reasonably cl= ear name is not sufficient if there
are other scripts that perform simi= lar tasks.

One approach that seems to be working so far is to combi= ne several scripts
into one using argparse subparsers. This results in = more frequent usage
which means I can get away with short meaningless n= ames=2C and infrequent
actions are just one

$ xx -h

awa= y.




--Forwarded Message Attachment--
From: bre= amoreboy@yahoo.co.uk
To: python-list@python.org
Date: Tue=2C 3 Jun 20= 14 09:03:12 +0100
Subject: Re: Python 3 is killing Python

On=
 03/06/2014 07:30=2C Rustom Mody wrote:
>=3B On Tuesday=2C June 3=2C 2= 014 11:42:30 AM UTC+5:30=2C jmf wrote:
>=3B
>=3B>=3B after thin= king no
>=3B
>=3B Yes [Also called Oui]
>=3B

I'm ver= y puzzled over "thinking"=2C what context was this in as I've
kill-file= d our most illustrious resident unicode expert?

--
My fellow Py= thonistas=2C ask not what our language can do for you=2C ask
what you c= an do for our language.

Mark Lawrence

---
This email is = free from viruses and malware because avast! Antivirus protection is active= .
http://www.avast.co= m





--Forwarded Message Attachment--
F= rom: breamoreboy@yahoo.co.uk
To: python-list@python.org
Date: Tue=2C = 3 Jun 2014 09:05:55 +0100
Subject: Re: Lock Windows Screen GUI using pyt= hon

On 03/06/2014 08:53=2C Jaydeep Patil wrote:

Would y= ou please use the mailing list
https://mail.python.org/mailman/= listinfo/python-list or read and action
this https://wiki.python= .org/moin/GoogleGroupsPython to prevent us
seeing double line spaci= ng and single line paragraphs=2C thanks.

--
My fellow Pythonist= as=2C ask not what our language can do for you=2C ask
what you can do f= or our language.

Mark Lawrence

---
This email is free fr= om viruses and malware because avast! Antivirus protection is active.
http://www.avast.com




--Forwarded Message Attachment--
From: pm= iscml@gmail.com
CC: python-list@python.org
To: tjreedy@udel.edu
Da= te: Tue=2C 3 Jun 2014 11:31:14 +0300
Subject: Re: Benefits of asyncio
Hello=2C

On Mon=2C 02 Jun 2014 21:51:35 -0400
Terry Re= edy <=3Btjreedy@udel.edu>=3B wrote:

>=3B To all the great res= ponders. If anyone thinks the async intro is
>=3B inadequate and has = a paragraph to contribute=2C open a tracker issue.

Not sure about i= ntro (where's that?)=2C but docs
(https://docs.python.org/3/library/as= yncio.html) are pretty confusing
and bugs are reported=2C with no re= sponse:
= http://bugs.python.org/issue21365

>=3B
>=3B --
>= =3B Terry Jan Reedy

--
Best regards=2C
Paul = mailto:pmiscml@gmail.com



--Forwarded Messag= e Attachment--
From: DMusiige@sennheisercommunications.com
To: python= -list@python.org
Date: Tue=2C 3 Jun 2014 08:10:03 +0000
Subject: Auto= mating windows media player on win7

=0A= =0A= =0A= =0A= =0A= =0A= =0A=
=0A=

Hi guys=2C

=0A=

 =3B

=0A=

I have been fighting with au= tomating wmplayer but with no success.

=0A=

It looks to me that using th= e .OCX would be the best option. I found the code below on the net but I ca= nnot get it to work.

=0A=

I can see from device manage= r that a driver is started by I get no audio out.=0A=

=0A=

What am I doing wrong guys?&= nbsp=3B =3B =3B =3B =3B =3B =3B =3B =3B&nbs= p=3B =3B =3B =3B =3B =3B =3B =3B =3B = =3B =3B =3B =3B =3B =3B =3B =3B=0A=

=0A=

 =3B

=0A=

# this program will play MP= 3=2C WMA=2C MID=2C WAV files via the WindowsMediaPlayer

=0A=

from win32com.client import= Dispatch

=0A=

mp =3D Dispatch("WMPlayer.O= CX")

=0A=

tune =3D mp.newMedia("./pla= ys.wav")

=0A=

mp.currentPlaylist.appendIt= em(tune)

=0A=

mp.controls.play()=0A=

raw_input("Press Enter to s= top playing")=0A=

=0A=

mp.controls.stop()

=0A=

 =3B

=0A=

Br

=0A=

Deo

=0A=
=0A= =0A= =0A=

--Forwarded Message Attachment--
From: rosuav@gmail.com
CC: p= ython-list@python.org
Date: Tue=2C 3 Jun 2014 18:47:11 +1000
Subject:= Re: Benefits of asyncio

On Tue=2C Jun 3=2C 2014 at 4:36 PM=2C =
Marko Rauhamaa <=3Bmarko@pacujo.net>=3B wrote:
>=3B I have yet to = see that in practice. The "typical" thread works as
>=3B follows:
&= gt=3B
>=3B while True:
>=3B while request.incomplete(= ):
>=3B request.read() # block
>=3B = sql_stmt =3D request.process()
>=3B db.act(sql_stmt) = # block
>=3B db.commit() = # block
>=3B response =3D request.ok_response()
>=3B = while response.incomplete():
>=3B response.write() = # block
>=3B
>=3B The places marked with the "block"= comment are states with only one
>=3B valid input stimulus.
>=3B= ...
>=3B Yes=2C a "nest of callbacks" can get messy very quickly. Tha= t is why you
>=3B need to be very explicit with your states. Your clas= s needs to have a
>=3B state field named "state" with clearly named st= ate values.

Simple/naive way to translate this into a callback syst= em is like this:

def request_read_callback(request=2C data):
= request.read(data) # however that part works
if not request.incompl= ete():
request.process()

def write(request=2C data):
= request.write_buffer +=3D data
request.attempt_write() # sets up= callbacks for async writing

def request.process(self): # I know th= is isn't valid syntax
db.act(whatever) # may block but shouldn't for= long
db.commit() # ditto
write(self=2C response) # won't blo= ck


This works as long as your database is reasonably fast and = close
(common case for a lot of web servers: DB runs on same computer as= web
and application and etc servers). It's nice and simple=2C lets you = use a
single database connection (although you should probably wrap it i= n a
try/finally to ensure that you roll back on any exception)=2C and wo= n't
materially damage throughput as long as you don't run into problems.=
For a database driven web site=2C most of the I/O time will be waiting<= br>for clients=2C not waiting for your database.

Getting rid of tho= se blocking database calls means having multiple
concurrent transactions= on the database. Whether you go async or
threaded=2C this is going to h= appen. Unless your database lets you run
multiple simultaneous transacti= ons on a single connection (I don't
think the Python DB API allows that= =2C and I can't think of any DB
backends that support it=2C off hand)=2C= that means that every single
concurrency point needs its own database c= onnection. With threads=2C you
could have a pool of (say) a dozen or so= =2C one per thread=2C with each
one working synchronously=3B with asynci= o=2C you'd have to have one for
every single incoming client request=2C = or else faff around with
semaphores and resource pools and such manually= . The throughput you
gain by making those asynchronous with callbacks is= quite probably
destroyed by the throughput you lose in having too many = simultaneous
connections to the database. I can't prove that=2C obviousl= y=2C but I do
know that PostgreSQL requires up-front RAM allocation base= d on the
max_connections setting=2C and trying to support 5000 connectio= ns
started to get kinda stupid.

So how do you deal with the poss= ibility that the database will block?
"Pure" threading (one thread liste= ns for clients=2C spin off a thread
for each client=2C end the thread wh= en the client disconnects) copes
poorly=3B async I/O copes poorly. The t= hread pool copes well (you know
exactly how many connections you'll need= - one per thread in the
pool)=2C but doesn't necessarily solve the prob= lem (you can get all
threads waiting on the database and none handling o= ther requests).
Frankly=2C I think the only solution is to beef up the d= atabase so it
won't block for too long (and=2C duh=2C to solve any stupi= d locking
problems=2C because they WILL kill you :) ).

>=3B If= threads simplify an asynchronous application=2C that is generally done
= >=3B by oversimplifying and reducing functionality.

Which means t= hat I disagree with this statement. In my opinion=2C both
simple models = (pure threading and asyncio) can express the same
functionality=3B the h= ybrid thread-pool model may simplify things a bit
in the interests of re= source usage=3B but threading does let you think
about code the same way= for one client as for fifty=2C without any
change of functionality. Com= pare:

# Console I/O:
def print_menu():
print("1: Spam") print("2: Ham")
print("3: Quit")

def spam():
pr= int("Spam=2C spam=2C spam=2C spam=2C")
while input("Continue? ")!=3D= "NO!":
print("spam=2C spam=2C spam...")

def mainloop():<= br> print("Welcome!")
while True:
print_menu()
= x =3D int(input("What would you like? "))
if x =3D=3D 1: spa= m()
elif x =3D=3D 2: ham()
elif x =3D=3D 3: break
= else: print("I don't know numbers like %d."%x)
print("Goodby= e!")


I could translate this into a pure-threading system very = easily:

# Socket I/O:
import consoleio
class TerminateRequest= (Exception): pass
tls =3D threading.local()
def print(s):
tls.= socket.write(s+"\r\n") # Don't forget=2C most of the internet uses \r\n!
def input(prompt):
tls.socket.write(s)
while '\n' not i= n tls.readbuffer:
tls.readbuffer +=3D tls.socket.read()
= if not tls.socket.connected(): raise TerminateRequest
ret=2C _=2C= tls.readbuffer =3D tls.readbuffer.partition("\n")
return ret.strip(= "\r")

consoleio.print =3D print
consoleio.input =3D input
def thread(sock):
tls.socket =3D sock
tls.readbuffer =3D ""=
try: consoleio.mainloop()
except TerminateRequest: pass
=
mainsock =3D socket.socket() # bind to port=2C whatever
mainsock.lis= ten(5)
while True:
threading.Thread(target=3Dthread=2Cargs=3D(mai= nsock.accept()=2C))


The only changes I made to the application= main loop are to change
(via injection) print and input to use the sock= et. Everything else -
the (bad) logic inside spam()=2C helper functions= =2C etc=2C etc - works
exactly the same way. So if you're coming from a = single-thread
single-client starting point=2C it's definitely way simple= r to follow a
model like this. (And I have written enough programs along= this sort
of line to be able to write the above without more than some = quick
checks to see how thread-local storage is done in Python. It's areally simple model. On the flip side=2C that does also mean the code
= above is completely untested=2C not to mention stubby in places=2C so itprobably won't actually run.)

How do you translate that to asynchr= onous I/O? Normally=2C with piles
and piles of callbacks. I haven't look= ed into tulip yet=2C but my
understanding is that it may be possible to = tulipify the above code in
the same way that I socketified it - you'd si= mply have a "yield from"
inside input()=2C which would let the system go= and deal with other
requests=3B but otherwise=2C you would need to comp= letely rewrite the main
code. The exact same functionality would look a = lot messier=3B and you
have the exact same problems to deal with either = way. Your connection
state has to cope with both input and output buffer= s (since you have
to make sure you don't block inside print() either)=2C= and while you can
in most applications assume that there won't be a hug= e amount of
output buffering (and can therefore let mainloop() pretend t= hat it all
got written instantly=2C while the actual writing happens in = the
background)=2C sometimes you have to be explicit about that part of<= br>state too. So the consoleio module above would need a lot of separatestates: every single print() or input() call becomes its own state=2C inwhich the connection might stall. Do you really want to do that with
c= allbacks? Because it would *definitely* be less clear.

ChrisA
<= br>


--Forwarded Message Attachment--
From: rosuav@gmail.com=
CC: python-list@python.org
Date: Tue=2C 3 Jun 2014 18:57:35 +1000Subject: Re: Automating windows media player on win7

On Tue=2C=
 Jun 3=2C 2014 at 6:10 PM=2C Deogratius Musiige
<=3BDMusiige@sennheise= rcommunications.com>=3B wrote:
>=3B Hi guys=2C
>=3B
>=3B>=3B
>=3B I have been fighting with automating wmplayer but with n= o success.
>=3B
>=3B It looks to me that using the .OCX would be = the best option. I found the
>=3B code below on the net but I cannot g= et it to work.
>=3B
>=3B I can see from device manager that a dri= ver is started by I get no audio
>=3B out.
>=3B
>=3B What am= I doing wrong guys?
>=3B
>=3B
>=3B
>=3B # this program= will play MP3=2C WMA=2C MID=2C WAV files via the WindowsMediaPlayer
>= =3B
>=3B from win32com.client import Dispatch
>=3B
>=3B mp = =3D Dispatch("WMPlayer.OCX")
>=3B
>=3B tune =3D mp.newMedia("./pl= ays.wav")
>=3B
>=3B mp.currentPlaylist.appendItem(tune)
>=3B=
>=3B mp.controls.play()
>=3B
>=3B raw_input("Press Enter to= stop playing")
>=3B
>=3B mp.controls.stop()
>=3B
>=3B<= br>>=3B
>=3B Br
>=3B
>=3B Deo

First suggestion: po= st plain text to this list=2C not HTML. You don't
need it to look like t= he above. :)

Secondly: Is there a particular reason that you need t= o be automating
Windows Media Player specifically? I have a similar proj= ect which
works by sending keystrokes=2C which means it works with anyth= ing that
reacts to keys=3B mainly=2C I use it with VLC. It can invoke a = movie or
audio file=2C can terminate the process=2C and can send a varie= ty of
commands via keys. It's designed to be used on a (trusted) LAN.
Code is here:
https://github.com/Rosuav/Yosemite

Once something'= s invoked by the Yosemite project=2C it simply runs as
normal inside VLC= . Easy to debug audio problems=2C because they're
managed the exact same= way. Granted=2C this does assume that it's given
full control of the sc= reen (it's designed to manage full-screen video
playback=3B in fact=2C m= y siblings are right now watching Toy Story 3 in
the other room=2C using= an old laptop driving a TV via S-Video=2C all
managed via the above pro= ject)=2C so it may not be ideal for background
music on a computer you u= se for other things=3B but feel free to borrow
ideas and/or code from th= ere. (And for what it's worth=2C I use this as
one of my sources of BGM = when I'm coding - just let it invoke the
file=2C then manually flip focu= s back to what I'm doing.)

ChrisA



--Forwarded= Message Attachment--
From: rosuav@gmail.com
CC: python-list@python.o= rg
Date: Tue=2C 3 Jun 2014 19:11:02 +1000
Subject: Re: Lock Windows S= creen GUI using python

On Tue=2C Jun 3=2C 2014 at 5:53 PM=2C Ja=
ydeep Patil <=3Bpatil.jay2009@gmail.com>=3B wrote:
>=3B
>=3B = During copy paste of excel data=2C if user by mistake doing some copy &= =3B paste operation outside excel(for e.g. doing copy paste in outlook mail= s=2C firefox browser etc)=2C it may be cause for the another error.
>= =3B
>=3B How i can control this?

Suggestion: Don't. If you rea= lly need this level of control of the
workstation=2C you are going about= things wrongly. This is a recipe for
fragility and horrific usability p= roblems. There are two simple
solutions:

1) Make it really obvio= us that you're controlling the computer=2C by
putting something big acro= ss the screen - a splash screen=2C of sorts -
which is set to Always On = Top and gives a message. And then just trust
that the user won't do anyt= hing=2C because you've done everything
reasonable. No further control ne= eded.

2) Automate your code by moving stuff around on the disk=2C *= not* by
actually working through Excel. Twenty minutes of Excel automati= on
should probably become a proper application that reads in some dataand generates some graphs. And it'd probably be faster=2C too (even ifExcel's performance is stellar=2C which I very much doubt=2C it's alwaysslower to work through a GUI than to do the work directly). Figure outwhat you're really trying to do=2C and do that directly.

Also=2C p= lease follow Mark's advice.

ChrisA



--Forwarde= d Message Attachment--
From: marko@pacujo.net
To: python-list@python.= org
Date: Tue=2C 3 Jun 2014 12:10:12 +0300
Subject: Re: Benefits of a= syncio

Chris Angelico <=3Brosuav@gmail.com>=3B:

>= =3B def request.process(self): # I know this isn't valid syntax
>=3B = db.act(whatever) # may block but shouldn't for long
>=3B db.com= mit() # ditto
>=3B write(self=2C response) # won't block
>=3B=
>=3B This works as long as your database is reasonably fast and close=

I find that assumption unacceptable.

The DB APIs desperate= ly need asynchronous variants. As it stands=2C you
are forced to delegat= e your DB access to threads/processes.

>=3B So how do you deal wi= th the possibility that the database will block?

You separate the r= equest and response parts of the DB methods. That's
how it is implemente= d internally anyway.

Say no to blocking APIs.

>=3B but ot= herwise=2C you would need to completely rewrite the main code.

That= 's a good reason to avoid threads. Once you realize you would have
been = better off with an async approach=2C you'll have to start over. You
can = easily turn a nonblocking solution into a blocking one but not the
other= way around.


Marko



--Forwarded Message A= ttachment--
From: rosuav@gmail.com
CC: python-list@python.org
Date= : Tue=2C 3 Jun 2014 19:30:14 +1000
Subject: Re: Benefits of asyncio
<= br>
On Tue=2C Jun 3=2C 2014 at 7:10 PM=2C Marko Rauhamaa <=3Bmarko@pa=
cujo.net>=3B wrote:
>=3B Chris Angelico <=3Brosuav@gmail.com>=3B= :
>=3B
>=3B>=3B def request.process(self): # I know this isn't = valid syntax
>=3B>=3B db.act(whatever) # may block but shouldn't= for long
>=3B>=3B db.commit() # ditto
>=3B>=3B write= (self=2C response) # won't block
>=3B>=3B
>=3B>=3B This works= as long as your database is reasonably fast and close
>=3B
>=3B = I find that assumption unacceptable.

It is a dangerous assumption.<= br>
>=3B The DB APIs desperately need asynchronous variants. As it st= ands=2C you
>=3B are forced to delegate your DB access to threads/proc= esses.
>=3B
>=3B>=3B So how do you deal with the possibility th= at the database will block?
>=3B
>=3B You separate the request an= d response parts of the DB methods. That's
>=3B how it is implemented = internally anyway.
>=3B
>=3B Say no to blocking APIs.

Oka= y=2C but how do you handle two simultaneous requests going through
the p= rocessing that you see above? You *MUST* separate them onto two
transact= ions=2C otherwise one will commit half of the other's work. (Or
are you = forgetting Databasing 101 - a transaction should be a logical
unit of wo= rk?) And since you can't=2C with most databases=2C have two
transactions= on one connection=2C that means you need a separate
connection for each= request. Given that the advantages of asyncio
include the ability to sc= ale to arbitrary numbers of connections=2C it's
not really a good idea t= o then say "oh but you need that many
concurrent database connections". = Most systems can probably handle a
few thousand threads without a proble= m=2C but a few million is going to
cause major issues=3B but most databa= ses start getting inefficient at a
few thousand concurrent sessions.
=
>=3B>=3B but otherwise=2C you would need to completely rewrite the= main code.
>=3B
>=3B That's a good reason to avoid threads. Once= you realize you would have
>=3B been better off with an async approac= h=2C you'll have to start over. You
>=3B can easily turn a nonblocking= solution into a blocking one but not the
>=3B other way around.
<= br>Alright. I'm throwing down the gauntlet. Write me a purely nonblockingweb site concept that can handle a million concurrent connections=2C
w= here each one requires one query against the database=2C and one in a
hu= ndred of them require five queries which happen atomically. I can do
it = with a thread pool and blocking database queries=2C and by matching
the = thread pool size and the database concurrent connection limit=2C I
can m= anage memory usage fairly easily=3B how do you do it efficiently
with pu= re async I/O?

ChrisA



--Forwarded Message Atta= chment--
From: rosuav@gmail.com
CC: python-list@python.org
Date: T= ue=2C 3 Jun 2014 19:46:27 +1000
Subject: Re: Automating windows media pl= ayer on win7

On Tue=2C Jun 3=2C 2014 at 7:42 PM=2C Deogratius M=
usiige
<=3BDMusiige@sennheisercommunications.com>=3B wrote:
>= =3B Hi Chris=2C
>=3B
>=3B I want to have wmplayer as part of my a= utomitized test for a headset via the
>=3B USB HID.
>=3B
>= =3B I want to be able to execute some of the following operations in my pyt= hon
>=3B script:
>=3B
>=3B 1. Play
>=3B
>=3B= 2. Get playing track
>=3B
>=3B 3. Next
>=3B
= >=3B 4. Get active device
>=3B
>=3B 5. =85
>= =3B
>=3B I am not sure if you are able to do this with your project
Play=2C definitely. Next=2C not specifically=2C but by sending the le= tter
'n' you can achieve that. Active device? Not sure what you mean the= re.

The one part that doesn't exist is "Get playing track". But you= could
manage this the other way around=2C by not invoking a playlist at= all.
If you run "vlc --play-and-exit some_file.wav"=2C then when that p= rocess
terminates=2C the track has finished. Kill the process or send Ct= rl-Q to
skip to the next track. Keep track (pun intended) of what file y= ou've
most recently invoked.

I'm not sure how this ties in with = your headset testing=2C though.

By the look of things=2C the Yosemi= te project isn't a "here it is=2C just
deploy it" solution=2C but you ma= y find that there's some useful code
you can borrow.

ChrisA
=
= --_2983b314-d991-4a3a-affa-83d4803b8da0_--