Re: Asyncio -- delayed calculation

2016-11-28 Thread Marko Rauhamaa
Gregory Ewing : > All the terminology around async/await is inherently confusing and > counterintuitive, IMO. I'm disappointed that we've ended up here. I think the conceptual mess can be clarified over time. Coroutines are essentially threads. Why Python needs two threading implementations is que

Re: correct way to catch exception with Python 'with' statement

2016-11-28 Thread Ganesh Pal
Thanks Steve I got what you were trying to explain , nice learning from this conversation , what I was really doing wrong I had broken down my huge code into a simple program and had missed out returning False. On Tue, Nov 29, 2016 at 11:01 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.

Re: Asyncio -- delayed calculation

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 4:32 PM, Steven D'Aprano wrote: > On Tuesday 29 November 2016 14:21, Chris Angelico wrote: > >> On Tue, Nov 29, 2016 at 1:23 PM, Steve D'Aprano >> wrote: >>> This is confusing: why is this awaiting something inside an async function? >>> Doesn't that mean that the await as

Re: Asyncio -- delayed calculation

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 4:13 PM, Paul Rubin wrote: > > I haven't gotten my head around Python asyncio and have been wanting > to read this: > >http://lucumr.pocoo.org/2016/10/30/i-dont-understand-asyncio/ It's talking a lot about how we got here, which isn't all necessary if you just want to

Re: Asyncio -- delayed calculation

2016-11-28 Thread Steven D'Aprano
On Tuesday 29 November 2016 14:21, Chris Angelico wrote: > On Tue, Nov 29, 2016 at 1:23 PM, Steve D'Aprano > wrote: >> This is confusing: why is this awaiting something inside an async function? >> Doesn't that mean that the await asyncio.gather(...) call is turned >> blocking? > > "await" means

Re: correct way to catch exception with Python 'with' statement

2016-11-28 Thread Steven D'Aprano
On Tuesday 29 November 2016 02:18, Ganesh Pal wrote: > On Mon, Nov 28, 2016 at 1:16 PM, Steven D'Aprano < > steve+comp.lang.pyt...@pearwood.info> wrote: > >> >> >> There is no need to return True. The function either succeeds, or it >> raises an >> exception, so there is no need to return any val

Re: Asyncio -- delayed calculation

2016-11-28 Thread Paul Rubin
Chris Angelico writes: > Asynchronous I/O is something to get your head around I'd much > rather work with generator-based async functions... I haven't gotten my head around Python asyncio and have been wanting to read this: http://lucumr.pocoo.org/2016/10/30/i-dont-understand-asyncio/

Re: Asyncio -- delayed calculation

2016-11-28 Thread Nathan Ernst
To be fair, in other languages, such as C# or C++ with similar mechanisms, if you don't ask for the result from an async or future task, there's no guarantee the async task will be executed at all unless (or until) you ask for the result. C++'s futures even give an explicit flag indicating you want

Re: Asyncio -- delayed calculation

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 3:16 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> "await" means "don't continue this function until that's done". It >> blocks the function until a non-blocking operation is done. > > > However, *not* using 'await' doesn't mean the operation > will be done without

Re: Asyncio -- delayed calculation

2016-11-28 Thread Gregory Ewing
Chris Angelico wrote: "await" means "don't continue this function until that's done". It blocks the function until a non-blocking operation is done. However, *not* using 'await' doesn't mean the operation will be done without blocking. Rather, it won't be done at all (and is usually an error, b

Re: Asyncio -- delayed calculation

2016-11-28 Thread Zachary Ware
On Mon, Nov 28, 2016 at 6:48 AM, Steve D'Aprano wrote: > What am I doing wrong? Give yourself a bit more to debug with, since you're going to want to do something with the result your expensive calculation anyway: import asyncio class Counter: def __init__(self, i): self.count = 10

Re: Asyncio -- delayed calculation

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 1:23 PM, Steve D'Aprano wrote: > This is confusing: why is this awaiting something inside an async function? > Doesn't that mean that the await asyncio.gather(...) call is turned > blocking? "await" means "don't continue this function until that's done". It blocks the func

Re: Asyncio -- delayed calculation

2016-11-28 Thread Zentrader
Take a look at Doug Hellmann's example using multiprocessing at https://pymotw.com/2/multiprocessing/basics.html You should be able to substitute the count down example directly into the first example. -- https://mail.python.org/mailman/listinfo/python-list

Re: Asyncio -- delayed calculation

2016-11-28 Thread Steve D'Aprano
On Tue, 29 Nov 2016 12:03 am, Chris Angelico wrote: > On Mon, Nov 28, 2016 at 11:48 PM, Steve D'Aprano > wrote: >> When I try running that, I get no output. No error, no exception, the >> run_until_complete simply returns instantly. > > When I do, I get this warning: > > asynctest.py:17: Runtim

Re: Asyncio -- delayed calculation

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 11:20 AM, Steve D'Aprano wrote: > On Tue, 29 Nov 2016 02:53 am, Ian Kelly wrote: > >> In order for the coroutines to actually do anything, you need to >> schedule them in some way with the event loop. That could take the >> form of awaiting them from some other coroutine, o

Re: The Case Against Python 3

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 10:54 AM, Steve D'Aprano wrote: > Now you're just being silly, this isn't "anything", it is a specific design > decision: something which looks like, and is treated by the tokeniser, as a > string but is actually a hidden call to eval. > This, I think, is the crux. A "hidd

Re: Asyncio -- delayed calculation

2016-11-28 Thread Steve D'Aprano
On Tue, 29 Nov 2016 02:53 am, Ian Kelly wrote: > In order for the coroutines to actually do anything, you need to > schedule them in some way with the event loop. That could take the > form of awaiting them from some other coroutine, or passing them > directly to loop.run_until_complete or event_l

Re: The Case Against Python 3

2016-11-28 Thread Steve D'Aprano
On Tue, 29 Nov 2016 09:35 am, Gregory Ewing wrote: > Steve D'Aprano wrote: >> I daresay you are right that a sufficiently clever adversary may have >> found an exploit. But there's no sign that anyone actually did find an >> exploit, until f-strings made exploiting this trivial. > > The person wh

Re: The Case Against Python 3

2016-11-28 Thread Paul Rubin
Gregory Ewing writes: > I agree that f-strings are not to blame here. If we really want to > avoid breaking anyone's ill-conceived attempts at sandboxing eval, > we'd better not add anything more to the language, ever, because > nobody can foresee all the possible consequences. I'm surprised eval

Re: The Case Against Python 3

2016-11-28 Thread Gregory Ewing
Steve D'Aprano wrote: I daresay you are right that a sufficiently clever adversary may have found an exploit. But there's no sign that anyone actually did find an exploit, until f-strings made exploiting this trivial. The person who wrote the bug report found at least one way of exploiting it t

Re: ANN: JavaScrypthon 0.5, now with embedded evaluation of transpiled code

2016-11-28 Thread Eric S. Johansson
On 11/28/2016 2:02 PM, Amirouche Boubekki wrote: > Also, FWIW users are looking for a Javascript replacement that is real > Python, not another coffeescript. does this count? http://brython.info/ -- https://mail.python.org/mailman/listinfo/python-list

Re: ANN: JavaScrypthon 0.5, now with embedded evaluation of transpiled code

2016-11-28 Thread Amirouche Boubekki
On Sat, Nov 26, 2016 at 7:21 PM Alberto Berti < azazel+python-annou...@arstecnica.it> wrote: > Hi all, > Héllo! > i'm pleased to announce that JavaScripthon 0.5 has been released to > PyPI. JavaScrypthon can translate a subset of Python 3.5 code to ES6 > JavaScript producing beautiful and lean

correct way to catch exception with Python 'with' statement

2016-11-28 Thread g thakuri
Dear Python friends, Any suggestion on how to add exception and make the below program look better , I am using Python 2.7 and Linux def create_files_append(): """ """ try: os.makedirs

Re: correct way to catch exception with Python 'with' statement

2016-11-28 Thread Thomas 'PointedEars' Lahn
Ganesh Pal wrote: > I am using Python 2.7 and Linux As a rule of thumb¹, use at least Python 3.3 for new programs. > What will be the best way to catch the exception in the above program ? > Can we replace both the with statement in the above program with > something like below > > try: >

plot band structure

2016-11-28 Thread badr
Hello everybody I have an xml file for Band structure that I would like to plot like this https://pypi.python.org/pypi/pydass_vasp/0.1. I have download phyton and I want to know the code to use and how to run the program, I am beginer to use it , please I need a help,thank you in advance. Rega

Re: Simple Python equivalent for the shell command

2016-11-28 Thread Michael Torrie
On 11/28/2016 08:55 AM, Michael Torrie wrote: > Well Bash is really good at some things. Piping commands together is > one of those things. Python can do such things but not in as compact a > way. For one Python has no quick way of interfacing with subprograms as > if they were language-level co

Re: Immutability of Floats, Ints and Strings in Python

2016-11-28 Thread Random832
On Fri, Nov 25, 2016, at 06:33, Ned Batchelder wrote: > A Python implementation can choose when to reuse immutable objects and > when not to. Reusing a value has a cost, because the values have to > be kept, and then found again. So the cost is only paid when there's > a reasonable chance that the

Re: correct way to catch exception with Python 'with' statement

2016-11-28 Thread Michael Torrie
On 11/28/2016 08:18 AM, Ganesh Pal wrote: > On Mon, Nov 28, 2016 at 1:16 PM, Steven D'Aprano < > steve+comp.lang.pyt...@pearwood.info> wrote: > >> >> >> There is no need to return True. The function either succeeds, or it >> raises an >> exception, so there is no need to return any value at all. >

Re: Simple Python equivalent for the shell command

2016-11-28 Thread Michael Torrie
On 11/28/2016 08:08 AM, Ganesh Pal wrote: > I was trying to write a function that will return me the unique number > associated with each employee id.The command has the output in the below > pattern > > Linux-Box-1# employee_details ls > List of names: > 100910bd9 s7018 > 100d60003 s7019 > 1106

Re: Asyncio -- delayed calculation

2016-11-28 Thread Ian Kelly
On Mon, Nov 28, 2016 at 5:48 AM, Steve D'Aprano wrote: > Let's pretend that the computation can be performed asynchronously, so that > I can have all five Counter objects counting down in parallel. I have this: > > > import asyncio > > class Counter: > def __init__(self): > self.count

Re: Simple Python equivalent for the shell command

2016-11-28 Thread Ganesh Pal
I remembered that I might need to add an else condition if the emp_num does not exist , so re sending the updated code def get_unique_number(str(emp_id)): """ Return the unique number associated with each employee id """ out, err, rc = run("employee_details ls", timeout=600) emp_unum

Re: correct way to catch exception with Python 'with' statement

2016-11-28 Thread Ganesh Pal
On Mon, Nov 28, 2016 at 1:16 PM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > > > There is no need to return True. The function either succeeds, or it > raises an > exception, so there is no need to return any value at all. > > I returned True here ,because based on the result

Simple Python equivalent for the shell command

2016-11-28 Thread Ganesh Pal
I was trying to write a function that will return me the unique number associated with each employee id.The command has the output in the below pattern Linux-Box-1# employee_details ls List of names: 100910bd9 s7018 100d60003 s7019 110610bd3 s7020 100d60002 s7021 Linux-Box-1# employee_details

Re: Asyncio -- delayed calculation

2016-11-28 Thread Chris Angelico
On Mon, Nov 28, 2016 at 11:48 PM, Steve D'Aprano wrote: > When I try running that, I get no output. No error, no exception, the > run_until_complete simply returns instantly. When I do, I get this warning: asynctest.py:17: RuntimeWarning: coroutine 'Counter.count_down' was never awaited obj.co

Asyncio -- delayed calculation

2016-11-28 Thread Steve D'Aprano
I'm a complete and utter newbie when it comes to asynchronous programming, so I may have the entire concept backwards here. But treat this as a learning exercise rather than something I'd really do. Suppose I have a bunch of calculations to do: count down from 10. So I have a bunch of objects: cl