[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-20 Thread Martin Panter

Martin Panter added the comment:

If your event loop supports it, maybe you could use add_reader() etc as a 
workaround (roughly based off a different function of my own; this version 
completely untested):

async def sock_recvfrom(nonblocking_sock, *pos, loop, **kw):
while True:
try:
return nonblocking_sock.recvfrom(*pos, **kw)
except BlockingIOError:
future = Future(loop=loop)
loop.add_reader(nonblocking_sock.fileno(), future.set_result, None)
try:
await future
finally:
loop.remove_reader(nonblocking_sock.fileno())

I’m not very experienced with asyncio, but I imagine having general-purpose 
loop.wait_readable(file_descriptor) etc methods would make writing these kind 
of functions easier.

--
nosy: +martin.panter

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: How the heck does async/await work in Python 3.5

2016-02-20 Thread Paul Rubin
Steven D'Aprano  writes:
> "But frankly the stuff I'm seeing in this thread makes me sad for
> *literally every programming language in existence except for Erlang
> and maybe one or two others*, which altogether about six people use in
> total..."

Erlang microtasks are more a matter of the runtime environment than the
language.  It might be possible to have something like it in PyPy.

Other languages typically do concurrency with something like:

  1. threads - various hazards that can be avoided if you're careful
  2. callback chaining like in node.js - gets messy if the program
 is complicated, but conceptually simple
  3. explicit state machines with something like libevent in C --
 same as #2, simple but tedious
  4. lightweight threads/tasks like in GHC and Erlang -- very nice though
 requires a sophisticated runtime system
  5. cooperative multasking (small RTOS's, Forth, etc): simple, but
 apparently bug-prone when the program gets complicated

Python's async stuff seems to combine various of the above approaches
and (while I'm not saying it's objectively bad) the experiences I've had
with it so far have been confusing and unpleasant.  I do want to put
some effort into understanding asyncio, but so far threads have worked
ok for me.

OK Web Server (uses a separate C++ process for each page on the site)
looked straightforward and fast, though makes some architectural
impositions.

http://seastar-project.org/ seems interesting but I don't understand it
at the moment.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-20 Thread Larry Hudson via Python-list

On 02/20/2016 10:38 AM, wrong.addres...@gmail.com wrote:
[snip]

How complicated could this get in Python? Reading the numbers is one thing, and 
then placing the values in text boxes of the GUI.


If that is the only object of using these values, there is no conversions necessary.  The data 
is read as text (strings), and you could simply write them directly into the text boxes.  Of 
course, this is unlikely -- you surely want the actual numeric values for other purposes.  As 
already pointed out, if you know in advance what the data types are, the necessary conversions 
are trivial.  Just slightly more complex if you don't know the types in advance.


OTOH, the conversion from int or float back to strings is also trivial.  It's as simple as 
writing str(n), where n is an int OR a float -- it works automatically with either.  (Data 
typing in Python is dynamic, you generally don't need to specify the types.)  But if you want 
the strings to be in a specific format, this is also possible with a different syntax that lets 
you specify the output format.  As an example, assume the variable val is 1.97834, and the 
formatting string is "${:.2f}".format(val) -- this will give you the string '$1.98'.  This 
expression breaks down to:

$   ->  a literal dollar sign
{}  ->  a placeholder, it is where the formatted data will be put
:   ->  what follows is formatting code
.2  ->  round to, and print, two decimal places
f   ->  the data is a float
.format(val)  ->  the data to format

BTW, this leaves the variable val unchanged -- it is NOT rounded, it still holds its original 
precision.  It only affects how it is displayed.  You CAN round it if you want, but that's an 
entirely different function.


Naturally, learning all the formatting codes takes some effort, but it allows defining the 
appearance of the resulting strings in a very detailed and complete manner.  [Aside:  this is 
the "new" formatting method.  Python also supports an "old" method, which is very much like the 
way strings are formatted in the C language.]



Or can I write my own reading subroutines which can then be called like
ReadVBstyle 8, ND, NIN, NT
to make the code more readable?


ABSOLUTELY!!  Most Python programming consists of defining the functions and classes needed, 
which definitely makes Python more readable.  (Classes imply Object Oriented Programming. 
Python _allows_ OOP but does not _require_ it -- and is irrelevant here.  Ignore anything I say 
about classes and OOP!)  For your example here, it wouldn't _match_ the BASIC syntax, but would 
be used in an equivalent way.


In fact, if you find yourself writing functions (or classes) that could be general-purpose 
routines, it is a trivial matter to put them into a personal library which you can then use in 
future programs.  You don't need to rewrite them, just use them.


Now, in practice, it takes a little care to write them as library functions.  That is, the 
original version may rely on some details of the original program, so the library version will 
need to be tweaked a bit to remove these 'local' dependencies.  But this is generally easily 
handled through the parameters to the functions.  Also they are probably written with a bit more 
care to handle error conditions (which Python calls exceptions, Python has very extensive 
exception handling).  This capability (a personal library) is enormously convenient.  While I am 
saying 'personal', I really mean library(s) available to everyone involved in a programming 
project.  No need for anyone to re-invent the wheel!  ;-)Python calls them modules rather 
than libraries, but it's the same thing.


 -=- Larry -=-

--
https://mail.python.org/mailman/listinfo/python-list


Re: How the heck does async/await work in Python 3.5

2016-02-20 Thread Steven D'Aprano
On Sat, 20 Feb 2016 05:44 pm, Paul Rubin wrote:

> But frankly the stuff I'm seeing in this thread makes me sad for Python.
> It's an impossible dream but it would be awesome to have Erlang-like
> communicating microtasks in Python.

"But frankly the stuff I'm seeing in this thread makes me sad for *literally
every programming language in existence except for Erlang and maybe one or
two others*, which altogether about six people use in total..."

:-)





-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I can't install python on my pc

2016-02-20 Thread Steven D'Aprano
On Sat, 20 Feb 2016 06:34 pm, Giriprasadh Raghavan wrote:

> 
> I can’t install python on my pc because it encounters an error every time
> I try to install it. Please help as soon as possible. Sent from Mail for
> Windows 10


Shall we guess what the error says?

My guess is that you are out of disk space. You need to delete some files,
or put in a bigger hard drive.



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


[issue21042] ctypes.util.find_library() should return full pathname instead of filename in linux

2016-02-20 Thread Martin Panter

Martin Panter added the comment:

Tamás, it might be a good idea for you to sign a contributor agreement 
.

I compiled Python in 32-bit mode and tried your v2 patch out, which found the 
wrong library as I predicted. Then I tried your new regex and it picked out the 
correct line. I had to edit it to get it to extract just the filename from the 
line:

r'lib%s\.[^\s]+\s\(%s(?:,\s.*)?\)\s=>\s(.*)' % (re.escape(name), abi_type)

I factored out the closing bracket from the comma + space bit, moved the group 
brackets to the end to extract the filename, and made it a raw string.

Without the patch, in 32-bit mode it will find 64-bit-only libraries:

>>> find_library("m")  # 32- and 64-bit available
'libm.so.6'
>>> find_library("tcl8.6")  # Only 64-bit version available!
'libtcl8.6.so'

With my edited regex:

>>> find_library("m")
'/usr/lib32/libm.so.6'
>>> find_library("tcl8.6") is None  # No 32-bit version found
True

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-20 Thread Mike S via Python-list

On 2/19/2016 8:58 PM, Denis Akhiyarov wrote:

On Wednesday, February 17, 2016 at 1:49:44 PM UTC-6, wrong.a...@gmail.com wrote:

I am mostly getting positive feedback for Python.

It seems Python is used more for web based applications. Is it equally fine for 
creating stand-alone *.exe's? Can the same code be compiled to run on Linux or 
Android or web-based?

Is it possible to create GUI elements with a good IDE? Can they be defined like 
in Visual Basic with given sizes, fonts, visible/invisible, etc.?

Is it easy to do matrix operations in Python? Or do I need to write subroutines 
like in Visual Basic?

Could someone kindly tell me advantages and disadvantages of Python? Or any 
better options? I have like 40-50 VB Forms and may be around 2 lines of 
code. It will be a task to learn a new language and translate/re-write that 
code.

Thanks for your responses.


I'm surprised that no one mentioned this tool called vb2py.
> It looks outdated, but I actually used it successfully to convert vba 
code to python,> once all dependencies were installed correctly :)

http://vb2py.sourceforge.net/
You can also understand how vb objects map to python objects.
vb2py has also minimal support for GUI conversion.
Someone has even forked it on github recently:
https://github.com/reingart/vb2py


Thanks! I have a lot of VB6 and VB.NET code and I'm learning Python 
thinking about doing machine learning, this might come in handy for 
other programs!

--
https://mail.python.org/mailman/listinfo/python-list


[issue26397] Tweak importlib Example of importlib.import_module() to use importlib.util.module_from_spec()

2016-02-20 Thread Brett Cannon

Changes by Brett Cannon :


--
resolution:  -> fixed
stage: needs patch -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26397] Tweak importlib Example of importlib.import_module() to use importlib.util.module_from_spec()

2016-02-20 Thread Roundup Robot

Roundup Robot added the comment:

New changeset f2a089d68297 by Brett Cannon in branch 'default':
Issue #26397: Update an importlib example to use util.module_from_spec() 
instead of create_module()
https://hg.python.org/cpython/rev/f2a089d68297

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26186] LazyLoader rejecting use of SourceFileLoader

2016-02-20 Thread Brett Cannon

Brett Cannon added the comment:

This has been resolved by removing the check (the docs have always said the 
method was ignored, so that will just continue). I also did separate commit to 
list that BuiltinImporter and ExtensionFileLoader won't work (they would need 
to be updated to return a module subclass to work).

I'm leaving this issue open to decide if I want to add an explicit check in 
importlib.util.LazyLoader.create_module() to verify that None is returned in 
Python 3.5 (I probably will, but I want to think about on it for a little bit).

--
resolution:  -> fixed
stage: test needed -> resolved

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26186] LazyLoader rejecting use of SourceFileLoader

2016-02-20 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 9f1e680896ef by Brett Cannon in branch '3.5':
Issue #26186: Remove an invalid type check in
https://hg.python.org/cpython/rev/9f1e680896ef

New changeset 86fc6cdd65de by Brett Cannon in branch 'default':
Merge for issue #26186
https://hg.python.org/cpython/rev/86fc6cdd65de

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26388] Disabling changing sys.argv[0] with runpy.run_module(...alter_sys=True)

2016-02-20 Thread Mike Kaplinskiy

Changes by Mike Kaplinskiy :


--
keywords: +patch
Added file: http://bugs.python.org/file41981/patch.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26221] awaiting asyncio.Future swallows StopIteration

2016-02-20 Thread Guido van Rossum

Guido van Rossum added the comment:

I think TypeError is fine. I would make the message a bit longer to
explain carefully what's the matter.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26221] awaiting asyncio.Future swallows StopIteration

2016-02-20 Thread Chris Angelico

Chris Angelico added the comment:

POC patch, no tests. Is TypeError right? Should it be ValueError, since the 
notional type is "Exception"?

--
keywords: +patch
Added file: http://bugs.python.org/file41980/no_stop_iter.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26397] Tweak importlib Example of importlib.import_module() to use importlib.util.module_from_spec()

2016-02-20 Thread Brett Cannon

New submission from Brett Cannon:

The example uses `spec.loader.create_module()` where it should be using 
`util.module_from_spec(spec)`.

--
assignee: brett.cannon
components: Documentation
messages: 260589
nosy: brett.cannon
priority: normal
severity: normal
stage: needs patch
status: open
title: Tweak importlib Example of importlib.import_module() to use 
importlib.util.module_from_spec()
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-20 Thread Simon Bernier St-Pierre

Simon Bernier St-Pierre added the comment:

I want to have a loop that receives data like this:

socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
socket.bind(('0.0.0.0', port))
socket.setblocking(False)
while True:
data, addr = await loop.sock_recvfrom(sock, 4096)
# process packet

It's pretty similar to what the blocking code would look like, but it allows me 
to keep everything on a single thread without blocking. It could be done with 
the Protocol API, but I'd rather use the shiny new async/await API.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26396] Create json.JSONType

2016-02-20 Thread Brett Cannon

New submission from Brett Cannon:

See https://github.com/python/typing/issues/182 for the full details, but it 
should be:

JSONType = t.Union[str, int, float, bool, None, t.Dict[str, t.Any], t.List[Any]]

--
assignee: brett.cannon
components: Library (Lib)
messages: 260587
nosy: brett.cannon, gvanrossum
priority: low
severity: normal
stage: needs patch
status: open
title: Create json.JSONType
type: enhancement
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-20 Thread Guido van Rossum

Guido van Rossum added the comment:

I won't make you go through the PEP process, but I do think it's a bad
idea to add this. After all datagrams aren't guaranteed to arrive, so,
whil I don't know what protocol you're trying to implement, I think
you're probably better off writing the whole thing as a
DatagramProtocol subclass that handles all incoming packets.

If you need help writing your app's code it's probably better to ask
around on a mailing list.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-20 Thread Simon Bernier St-Pierre

Simon Bernier St-Pierre added the comment:

That could work. I came up with this

class MyProtocol(aio.DatagramProtocol):
def __init__(self, fut):
self._fut = fut

def datagram_received(self, data, addr):
self.fut.set_result((data, addr))

fut = aio.Future()
loop.create_datagram_endpoint(lambda: MyProtocol(fut), ...)
yield from fut

1. Is there a better way of sharing the future between the protocol and the 
main function?
2. This might be inefficient because I have to create a new endpoint every time 
I want to receive a packet. I might be able to implement a scheme where I give 
the protocol a new future after every packet, but it's kind of cumbersome.

If I wrote the patch to make sock_recvfrom work, can it get merged or must it 
go through the PEP process?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26221] awaiting asyncio.Future swallows StopIteration

2016-02-20 Thread Guido van Rossum

Guido van Rossum added the comment:

OK, since eventually there won't be a way to inject StopIteration into
a Future anyway (it'll always raise RuntimeError once PEP 479 is the
default behavior) we should just reject this in set_exception().

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26000] Crash in Tokenizer - Heap-use-after-free

2016-02-20 Thread Sean Gillespie

Sean Gillespie added the comment:

Is anyone currently working on this? If not, I'd like to try and fix this. I've 
debugged this a little and think I have an idea of what's going on.

--
nosy: +swgillespie

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-20 Thread Guido van Rossum

Guido van Rossum added the comment:

You should be able to do this by calling create_datagram_endpoint(), passing it 
a custom DatagramProtocol subclass whose datagram_received() stores the data in 
the result of a Future. You can then wait for the Future to wait for the data 
(assuming it ever arrives :-).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24872] Add /NODEFAULTLIB:MSVCRT to _msvccompiler

2016-02-20 Thread Mark Mikofski

Mark Mikofski added the comment:

still have the `link.exe` 1561 error without `extra_args=['/DLL']` issue. is 
there a patch? It goes in `distutils._msvccompiler` right?

--
nosy: +bwanamarko

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26395] asyncio does not support yielding from recvfrom (socket/udp)

2016-02-20 Thread Simon Bernier St-Pierre

New submission from Simon Bernier St-Pierre:

I want to receive data on a UDP socket that was bound, without blocking the 
event loop. I've looked through the asyncio docs, and I haven't found a way of 
doing that using the coroutine API (yield from/await).

There is a sock_recv method on BaseEventLoop which is a coroutine, it seems 
like sock_recvfrom was never implemented.

I don't have a patch for this right now, I wanted to know what people thought 
of adding support for this.

--
components: asyncio
messages: 260580
nosy: Simon Bernier St-Pierre, gvanrossum, haypo, yselivanov
priority: normal
severity: normal
status: open
title: asyncio does not support yielding from recvfrom (socket/udp)
versions: Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21042] ctypes.util.find_library() should return full pathname instead of filename in linux

2016-02-20 Thread Tamás Bence Gedai

Tamás Bence Gedai added the comment:

What do you think about this regex?

'(lib%s\.[^\s]+\s\(%s(?:\)|,\s.*\))\s=>\s.*)' % (re.escape(name), abi_type))

It works on 64 bit, just like before, but I could not test it on 32 bit. I'll 
add tests soon.

I looked for documentation on ldconfig, but could not find anything useful.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-20 Thread Roel Schroeven

wrong.addres...@gmail.com schreef op 2016-02-19 11:47:

Thanks. The data I will often have to read from text files could read like

2 12.657823 0.1823467E-04 114 0
3 4 5 9 11
"Lower"
278.15

Is it straightforward to read this, or does one have to read one character at a 
time and then figure out what the numbers are?


The question is: what is known about the format of the data? Is it 
fixed, or does the code need to be smart enough to be able to deal with 
varying formats?


If we can assume that there are 4 lines, of which the first line 
contains floating point numbers, the second contains integers, the third 
contains one string and the fourth contains one floating point number, 
it's pretty easy. For example:


def readinput(filename):
with open(filename, 'rt') as f:
lines = f.readlines()
line0 = [float(part) for part in lines[0].split()]
line1 = [int(part) for part in lines[1].split()]
line2 = lines[2].strip()[1:-1]
line3 = float(lines[3])
return line0, line1, line2, line3

line0, line1, line2, line3 = readinput('input.txt')
print(line0)
print(line1)
print(line2)
print(line3)

Output:

[2.0, 12.657823, 1.823467e-05, 114.0, 0.0]
[3, 4, 5, 9, 11]
Lower
278.15

This basically splits the two first line by whitespace, then converts 
each part (or the whole line in case of the last two lines) into the 
desired data type.


--
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

Roel Schroeven

--
https://mail.python.org/mailman/listinfo/python-list


[issue26385] the call of tempfile.NamedTemporaryFile fails and leaves a file on the disk

2016-02-20 Thread Martin Panter

Martin Panter added the comment:

I think patch 3 is good for Python 3, thankyou. For Python 2, the test will 
have to be adjusted. From memory, mode='wr' is accepted without an exception, 
and mode=2 triggers an early error (so we never trigger the bug).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: asyncio - run coroutine in the background

2016-02-20 Thread Chris Angelico
On Sun, Feb 21, 2016 at 4:45 AM, Martin A. Brown  wrote:
> Another (non-Python) DNS name lookup library that does practically
> the same thing (along with the shortcomingsn you mentioned, Chris:
> no NSS nor /etc/hosts) is the adns library.  Well, it is DNS, after
> all.
>
>   http://www.gnu.org/software/adns/
>   https://pypi.python.org/pypi/adns-python/1.2.1
>
> And, there are Python bindings.  I have been quite happy using the
> adns tools (and tools built on the Python bindings) for mass lookups
> (millions of DNS names).  It works very nicely.
>
> Just sharing knowledge of an existing tool,
>

Ultimately, anything that replaces a gethostbyname/getaddrinfo call
with an explicit DNS lookup is going to have the exact same benefit
and downside: lookups won't freeze the program, but you can't use
/etc/hosts any more. (Slightly sloppy language but that's how an end
user will see it.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26221] awaiting asyncio.Future swallows StopIteration

2016-02-20 Thread Chris Angelico

Chris Angelico added the comment:

Ultimately, it's the exact same thing that PEP 479 is meant to deal with - 
raising StopIteration is functionally identical to returning. I don't use 
asyncio enough to be certain, but I'm not aware of any good reason to inject a 
StopIteration into it; maybe an alternative solution is to add a check in 
set_exception "if isinstance(exception, StopIteration): raise DontBeAFool"?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26367] importlib.__import__ does not fail for invalid relative import

2016-02-20 Thread Brett Cannon

Brett Cannon added the comment:

Thanks for the patch, Manuel!

--
resolution:  -> fixed
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26367] importlib.__import__ does not fail for invalid relative import

2016-02-20 Thread Roundup Robot

Roundup Robot added the comment:

New changeset e523efd47418 by Brett Cannon in branch '3.5':
Issue #26367: Have importlib.__init__() raise RuntimeError when
https://hg.python.org/cpython/rev/e523efd47418

New changeset 8f72bf88f471 by Brett Cannon in branch 'default':
Merge for issue #26367
https://hg.python.org/cpython/rev/8f72bf88f471

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26221] awaiting asyncio.Future swallows StopIteration

2016-02-20 Thread Guido van Rossum

Guido van Rossum added the comment:

Chris, can you help out here? I still don't understand the issue here. Since 
"from __future__ import generator_stop" only works in 3.5+ it would not work in 
Python 3.3/3.4 (supported by upstream asyncio with literally the same source 
code currently). If there's no use case for f.set_exception(StopIteration) 
maybe we should just complain about that?

--
nosy: +Rosuav

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26307] no PGO for built-in modules with `make profile-opt`

2016-02-20 Thread Brett Cannon

Changes by Brett Cannon :


--
stage:  -> needs patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24915] Profile Guided Optimization improvements (better training, llvm support, etc)

2016-02-20 Thread Brett Cannon

Brett Cannon added the comment:

Please add the fix to the issue that reported the problem so that the fix can 
be tracked with the bug report.

--
resolution:  -> fixed
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26394] Have argparse provide ability to require a fallback value be present

2016-02-20 Thread Brett Cannon

Changes by Brett Cannon :


--
title: argparse: Add set_values() function to complement set_defaults() -> Have 
argparse provide ability to require a fallback value be present

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: I can't install python on my pc

2016-02-20 Thread Oscar Benjamin
On 20 Feb 2016 14:05, "Giriprasadh Raghavan" 
wrote:
>
>
> I can’t install python on my pc because it encounters an error every time
I try to install it. Please help as soon as possible.

You need to give more information than that to get clear help. What error
do you see? If there is an error message what does it say? What exactly do
you do that results in the message?
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26394] argparse: Add set_values() function to complement set_defaults()

2016-02-20 Thread Brett Cannon

Brett Cannon added the comment:

To paraphrase Michael, he wants a way to tell argparse that an argument has to 
be supplied either from the command-line or some other mechanism (e.g., envvar, 
config file, etc.), but that if the value cannot be found in either situation, 
argparse fails saying the value is missing. This is different from a default 
value and making something optional as argparse has no way to signal that a 
default value isn't available, forcing the user to do the actual check 
externally to argparse itself. All of this stems from the fact that argparse's 
default argument stuff happens prior to parsing sys.argv and determining what 
is missing.

What this probably requires is a new keyword-only argument like `fallback` 
which is a callable which is only called if an accompanying value isn't found 
from sys.argv and which can raise some specific exception to signal that the 
fallback value couldn't be determined on top of missing from sys.argv.

--
nosy: +brett.cannon
stage:  -> test needed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26389] Expand traceback module API to accept just an exception as an argument

2016-02-20 Thread Brett Cannon

Brett Cannon added the comment:

So Terry's right that in my haste to write down the idea I contradicted myself. 
I do want to tweak the APIs in the traceback module to accept only an 
exception. The question is whether we need entirely new functions or if the 
pre-existing ones can be updated to work with just an exception.

And if we were to tweak the existing functions instead of add new ones, I would 
do it by making all arguments optional and adding a new keyword-only argument 
called `exc` that took the exception. Either `exc` would be set or the old 
arguments would need to all be set, and it would be an error to set both sets 
of arguments. And when the old arguments were taken away then all arguments for 
those functions would become keyword-only.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-20 Thread Christian Gollwitzer

Am 20.02.16 um 19:45 schrieb wrong.addres...@gmail.com:

On Saturday, 20 February 2016 09:54:15 UTC+2, Steven D'Aprano  wrote:

To answer your question "Do I need something fancy...?", no, of course not,
reading a line of numbers from a text file is easy.

with open("numbers.txt", "r") as f:
 for line in f:
 numbers = [int(s) for s in split(line)]



This looks good enough. This does not seem complicated (although I still 
understand almost nothing of what is written). I was simply not expressing 
myself in a way you people would understand.



will read and convert integer-valued numbers separated by whitespace like:

 123 654 9374 1 -45 3625


one line at a time. You can then collate them for later use, or process them
as you go. If they're floating point numbers, change the call to int() to a
call to float().



And I guess if the first three numbers are integers and the fourth is a float, 
then also there must be some equally straightforward way.


If you know in advance, what you expect, then it is easy. Most people 
who gave you answers assumed that you have a messy file and don't know 
if an int or float follows, and you want a program which decides by 
itself whether to read an int, float or string.


Whereas, if the format is fixed, for 3 ints and 1 float, you could do:

str='1 2 3 3.14159' # some example
fmt=(int,int,int,float) # define format
a,b,c,d=[type(x) for (type,x) in zip(fmt, str.split())]

It's one line, but it might look involved and actually it uses a list 
comprehension, tuple unpacking and first class functions, so it's 
certainly not comprehensible from the first Python lesson. Another 
alternative would be sscanf. This is a 3rd party module which simulates 
C sscanf, optimized more or less for this kind of number parsing:


https://hkn.eecs.berkeley.edu/~dyoo/python/scanf/

After installing that, you can do:

from scanf import sscanf
str='1 2 3 3.14159'
a,b,c,d=sscanf(str, '%d %d %d %f')

whereby '%d' means integer and '%f' is float. sscanf also handles 
fixed-width columns which you often get from Fortran programs.


Christian


--
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-20 Thread wrong . address . 1
On Saturday, 20 February 2016 06:58:39 UTC+2, Denis Akhiyarov  wrote:
> On Wednesday, February 17, 2016 at 1:49:44 PM UTC-6, wrong.a...@gmail.com 
> wrote:
> > I am mostly getting positive feedback for Python.
> > 
> > It seems Python is used more for web based applications. Is it equally fine 
> > for creating stand-alone *.exe's? Can the same code be compiled to run on 
> > Linux or Android or web-based?
> > 
> > Is it possible to create GUI elements with a good IDE? Can they be defined 
> > like in Visual Basic with given sizes, fonts, visible/invisible, etc.?
> > 
> > Is it easy to do matrix operations in Python? Or do I need to write 
> > subroutines like in Visual Basic?
> > 
> > Could someone kindly tell me advantages and disadvantages of Python? Or any 
> > better options? I have like 40-50 VB Forms and may be around 2 lines of 
> > code. It will be a task to learn a new language and translate/re-write that 
> > code.
> > 
> > Thanks for your responses.
> 
> I'm surprised that no one mentioned this tool called vb2py. It looks 
> outdated, but I actually used it successfully to convert vba code to python, 
> once all dependencies were installed correctly :)
> 
> http://vb2py.sourceforge.net/
> 
> You can also understand how vb objects map to python objects.
> 
> vb2py has also minimal support for GUI conversion.
> 
> Someone has even forked it on github recently:
> 
> https://github.com/reingart/vb2py

This will definitely be useful to me in the early phase.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-20 Thread wrong . address . 1
On Saturday, 20 February 2016 09:54:15 UTC+2, Steven D'Aprano  wrote:
> On Fri, 19 Feb 2016 10:53 pm, wrong.addres...@gmail.com wrote:
> 
> >> See http://nedbatchelder.com/text/python-parsers.html for a list of
> >> parsers that can do all sorts for you.  Or the stdlib re module
> > 
> > I am an engineer, and do not understand most of the terminology used
> > there. 
> 
> Google, or the search engine of your choice, is your friend.
> 
> https://duckduckgo.com/html/
> 
> https://startpage.com/eng/?
> 
> 
> Wikipedia even more so: Wikipedia has lots of good, useful articles on
> computing concepts.
> 
> https://en.wikipedia.org/wiki/Category:Computing
> 
> And use the search box visible at the top of every page.
> 
> Or ask here.
> 
> 
> 
> > And do I need something fancy to read a line of numbers? Should it 
> > not be built into the language?
> 
> In your own words:
> 
> "I will have to read data given to me by people, which may not come in nice
> formats like CSV"
> 
> I trust that you don't expect the language to come with pre-written
> functions to read numbers in every imaginable format. If you do, you will
> be disappointed -- no language could possible do this.
> 
> To answer your question "Do I need something fancy...?", no, of course not,
> reading a line of numbers from a text file is easy.
> 
> with open("numbers.txt", "r") as f:
> for line in f:
> numbers = [int(s) for s in split(line)]
> 

This looks good enough. This does not seem complicated (although I still 
understand almost nothing of what is written). I was simply not expressing 
myself in a way you people would understand.

> 
> will read and convert integer-valued numbers separated by whitespace like:
> 
> 123 654 9374 1 -45 3625
> 
> 
> one line at a time. You can then collate them for later use, or process them
> as you go. If they're floating point numbers, change the call to int() to a
> call to float().
> 

And I guess if the first three numbers are integers and the fourth is a float, 
then also there must be some equally straightforward way.

Thanks for this explanation, which changes my view about reading numbers in 
Python.

> 
> 
> 
> 
> 
> -- 
> Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-20 Thread wrong . address . 1
On Saturday, 20 February 2016 18:23:26 UTC+2, nholtz  wrote:
> On Wednesday, February 17, 2016 at 2:49:44 PM UTC-5, wrong.a...@gmail.com 
> wrote:
> > I am mostly getting positive feedback for Python.
> > ...
> 
> I'm surprised no one has mentioned jupyter yet, so here goes ...
> 
> A browser-based notebook, see http://www.jupyter.org
> 
> I think this is an unparalleled way to learn Python, by experimentation at 
> the start and for development later.  As an example, I wanted to do some table
> processing, so a couple of lines to experiment with Pandas reading CSV files, 
> then a couple of more lines to start processing the data ... What a wonderful 
> way to experimentally develop software ...
> 
> Can even develop simple GUIs *really* easily (but packaging for distribution 
> is probably not easy, unless distribution is only within an organization and 
> that organization can run a private notebook server).
> 
> If you want to try it, this page
> 
> http://jupyter.readthedocs.org/en/latest/install.html
> 
> recommends installing Anaconda Python which installs a *lot* of stuff (numpy, 
> scipy, sympy, pandas, etc. etc.)
> 
> I highly recommend both (I use them for Civil Engineering (structures) 
> software and teach a related university course)

Thanks. This gives me some more confidence that it will be a good choice for my 
work as well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-20 Thread wrong . address . 1
On Saturday, 20 February 2016 09:49:17 UTC+2, Larry Hudson  wrote:
> On 02/19/2016 10:14 AM, wrong.addres...@gmail.com wrote:
> [snip]
> >
> > This is precisely reading one character at a time. If not exactly reading 
> > one character, it is effectively looking at each character to assemble the 
> > number. Not a good sign. I guess there might be libraries which will help 
> > read numbers better, but I would expect a good language to be able to 
> > handle this basic thing for engineers - to read numbers like Fortran and 
> > Basic do.
> >
> > Still, if I have misunderstood something, I will be glad to be corrected. I 
> > would generally know that the first three numbers will be floating point, 
> > the next will be something and then the next will be something else, etc. 
> > Does that help or does one still have to look at each character and 
> > determine how to place it in a number?
> >
> > Thanks for your patience. I don't want surprises later on, which is why I 
> > am asking very stupid questions.
> >
> It absolutely does NOT require reading a character at a time!  You are 
> reading the data from a 
> text file, which means everything is a string.  These strings (or 
> sub-strings) can represent 
> integers, floats, dates, phone numbers or whatever.  Your example data 
> implies a free-form 
> style, where it is then necessary to determine the data type for each of 
> these (sub)strings 
> individually.  Of course, if your data has a defined fixed format, this is 
> simplified -- but 
> they are still initially strings that have to be converted.  String 
> processing in Python is very 
> powerful and versatile.
> 
> BTW, it does no good to continue to think strictly in BASIC techniques.  
> Python is a different 
> language with a different approach to attacking problems.  If you try to 
> write BASIC (or C or 
> Java or ...) programs in Python syntax you'll just get bad programs.  Forget 
> trying to find 
> features in Python that are identical to the features of BASIC.  Python 
> requires a different 
> mind-set to use it properly -- just like any other language.
> 
> Here is a rather naive somewhat brute-force way to read your example data.  
> I'm using a Python 
> list here to simulate the file reading.  (Actually, using read() instead of 
> readline() will also 
> give this list.)  Python lists are essentially the same as arrays in other 
> languages, but much 
> more powerful and versatile.  Two examples of the differences between arrays 
> and lists are:  can 
> use mixed data types, you are not restricted to all the same data type, and 
> the size of lists 
> are dynamic -- they grow or shrink as necessary.
> 
> Comments start with a #
> Strings in Python can be delimited by single-quotes ('), double-quotes (") or 
> triple-quotes (""" 
> or ''').  Triple-quoted strings can be multi-line text.  The triple-quote 
> here is used as what 
> Python calls a docstring, which it saves internally for documenting your 
> program.
> 
> 
> #   Define a function to determine the data type a string represents
> def chktyp(s):
>  """Check string s for int, float or string.  Returns the data and a type 
> code"""
>  try:
>  return int(s), 'int'  #  Try to convert to int, return it if 
> successful
>  except ValueError:#  No, it's not an int
>  pass  #  Drop into float test
>  try:
>  return float(s), 'float'  #  Try to convert to float, return it if 
> successful
>  except ValueError:#  No, it's not a float
>  return s, 'str'   #  It must be a string
> 
> #   Here is your (simulated) data as a list of strings
> data = [
>  '2 12.657823 0.1823467E-04 114 0',
>  '3 4 5 9 11',
>  '"Lower"',#  Could be left simply as "Lower"
>  '278.15']
> 
> #   Process the data
> for line in data: #  For each line of the data
>  dat = line.split()#  Make a list of the sub-strings in the 
> line
>  for stng in dat:  #  For each substring
>  dt, tp = chktyp(stng) #  Get the data and the type
>  print('{} is a {}'.format(dt, tp))#  Print this data
> 
> 
> Running this example gives this result:
> 
> 2 is a int
> 12.657823 is a float
> 1.823467e-05 is a float
> 114 is a int
> 0 is a int
> 3 is a int
> 4 is a int
> 5 is a int
> 9 is a int
> 11 is a int
> "Lower" is a str
> 278.15 is a float
> 
> I hope this gives you a slight hint about the Python way of doing things.  
> Yes, of course it's 
> very different from BASIC, but if you can pick up on the Pythonic way of 
> doing things I think 
> you might at least find it useful.
> 
>   -=- Larry -=-

I realise that this file i/o will have to be thought of in a different way if I 
start to use Python. This may still be worthwhile inspite of the complexity and 
loss in readability of the code.

To give an example of the kind of things I have to read (and I have 

[issue26336] Expose regex bytecode as attribute of compiled pattern object

2016-02-20 Thread Jonathan Goble

Jonathan Goble added the comment:

Noting for the record that, as I had brought up on python-ideas [1], in 
addition to simply exposing the raw code, it would be nice to have a public 
constructor for the compiled pattern type and a 'dis'-like module for support. 
The former would enable optimizers, and the latter would simplify programmatic 
analysis.

[1] 
https://mail.python.org/pipermail/python-ideas/2016-February/thread.html#38488

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: asyncio - run coroutine in the background

2016-02-20 Thread Martin A. Brown

Hello there,

I realize that this discussion of supporting asynchronous name 
lookup requests in DNS is merely a detour in this thread on asyncio, 
but I couldn't resist mentioning an existing tool.

>> getaddrinfo is a notorious pain but I think it's just a library 
>> issue; an async version should be possible in principle.  How 
>> does Twisted handle it?  Does it have a version?
>
>In a (non-Python) program of mine, I got annoyed by synchronous 
>name lookups, so I hacked around it: instead of using the regular 
>library functions, I just do a DNS lookup directly (which can then 
>be event-based - send a UDP packet, get notified when a UDP packet 
>arrives). Downside: Ignores /etc/nsswitch.conf and /etc/hosts, and 
>goes straight to the name server. Upside: Is able to do its own 
>caching, since the DNS library gives me the TTLs, but 
>gethostbyname/getaddrinfo won't.

Another (non-Python) DNS name lookup library that does practically 
the same thing (along with the shortcomingsn you mentioned, Chris: 
no NSS nor /etc/hosts) is the adns library.  Well, it is DNS, after 
all.

  http://www.gnu.org/software/adns/
  https://pypi.python.org/pypi/adns-python/1.2.1

And, there are Python bindings.  I have been quite happy using the 
adns tools (and tools built on the Python bindings) for mass lookups 
(millions of DNS names).  It works very nicely.

Just sharing knowledge of an existing tool,

-Martin

-- 
Martin A. Brown
http://linux-ip.net/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Problem with matplotlib

2016-02-20 Thread jenswaelkens
Op zaterdag 20 februari 2016 09:43:35 UTC+1 schreef Mark Lawrence:
> On 20/02/2016 07:42, jenswaelk...@gmail.com wrote:
> > When I use either of the following commands I get an error for which I 
> > don't have a solution, could someone here help me further?
> > These are the commands:
> > import matplotlib.pyplot as plt
> 
> Are you certain that this is what you typed?
> 
> C:\Users\Mark\Desktop>py -2.7
> Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit 
> (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import matplotlib.pyplot as plt
>  >>>
> 
> Please have another go.
> 
> >
> > or
> >
> > from matplotlib.pyplot import pyplot as plt
> 
> The above is incorrect, you are trying to import 'pyplot' from 
> 'matplotlib.pyplot'.

You are right, this doesn't work, I got it from some source on the Internet 
tryin to solve the initial problem with the other statement...Anyway, as you 
see in my other reply, the problem has been solved.

kind regards,
Jens

> 
> >
> > This is the error I get:
> > Traceback (most recent call last):
> >File "/home/waelkens/matplotlibdemo.py", line 2, in 
> >  from matplotlib.pyplot import pyplot as plt
> >File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 27, 
> > in 
> >  import matplotlib.colorbar
> >File "/usr/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 36, 
> > in 
> >  import matplotlib.contour as contour
> >File "/usr/lib/python2.7/dist-packages/matplotlib/contour.py", line 17, 
> > in 
> >  import matplotlib.ticker as ticker
> >File "/usr/lib/python2.7/dist-packages/matplotlib/ticker.py", line 152, 
> > in 
> >  import decimal
> >File "/usr/lib/python2.7/decimal.py", line 3744, in 
> >  _numbers.Number.register(Decimal)
> > AttributeError: 'module' object has no attribute 'Number'
> >
> > thanks in advance
> > Jens
> >
> 
> With this type of problem I'm inclined to throw the last line of the 
> traceback, here the 'AttributeError' one, into a search engine and see 
> what you come up with.  The hits you get are often enough to help you 
> diagnose the problem.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Problem with matplotlib

2016-02-20 Thread jenswaelkens
Op zaterdag 20 februari 2016 09:50:05 UTC+1 schreef Dave Farrance:
> It occurs to me now that the trackback might misidentify the module in
> use, if say, you'd named a file "numbers.py" then got rid of it later
> leaving a "numbers.pyc" somewhere. If so, see where it is:
> 
> import numbers
> print numbers.__file__

Dear Farrance,
You have solved my problem, there was indeed a program which I had called 
numbers.py and a numbers.pyc which caused this behaviour. Thanks a lot for 
helping me.

kind regards,
Jens
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-20 Thread nholtz
On Wednesday, February 17, 2016 at 2:49:44 PM UTC-5, wrong.a...@gmail.com wrote:
> I am mostly getting positive feedback for Python.
> ...

I'm surprised no one has mentioned jupyter yet, so here goes ...

A browser-based notebook, see http://www.jupyter.org

I think this is an unparalleled way to learn Python, by experimentation at the 
start and for development later.  As an example, I wanted to do some table
processing, so a couple of lines to experiment with Pandas reading CSV files, 
then a couple of more lines to start processing the data ... What a wonderful 
way to experimentally develop software ...

Can even develop simple GUIs *really* easily (but packaging for distribution is 
probably not easy, unless distribution is only within an organization and that 
organization can run a private notebook server).

If you want to try it, this page

http://jupyter.readthedocs.org/en/latest/install.html

recommends installing Anaconda Python which installs a *lot* of stuff (numpy, 
scipy, sympy, pandas, etc. etc.)

I highly recommend both (I use them for Civil Engineering (structures) software 
and teach a related university course)
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26394] argparse: Add set_values() function to complement set_defaults()

2016-02-20 Thread Michael Herold

New submission from Michael Herold:

argparse has at least three features to set defaults (default=, set_defaults(), 
 argument_default=). However, there is no feature to set the values of 
arguments.

The difference is, that a required argument has to be specified, also if a 
default value exists. Thus, a clean way to set values from config files or env 
variables does not exist without making all arguments optional.

See for example 
,
 where it becomes clear that no general solution for all actions exists. As a 
result, people also start to mess around with the args parameter of 
parse_args(). Even ConfigArgParse (used by Let's Encrypt) seems to fail in 
doing this properly.

So please add a set_values() function, similar to set_defaults(). The 
predefined value should be treated as if it had been entered on the command 
line. If the value has also been supplied via the command line, the predefined 
value is overwritten.

--
components: Library (Lib)
messages: 260568
nosy: quabla
priority: normal
severity: normal
status: open
title: argparse: Add set_values() function to complement set_defaults()
type: enhancement
versions: Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4928] Problem with tempfile.NamedTemporaryFile

2016-02-20 Thread Eryk Sun

Eryk Sun added the comment:

Maybe a note could be added to suggest using a SIGTERM signal handler (e.g. the 
handler could raise a SIGTERM exception):

POSIX: The file will not be deleted if the process is terminated abruptly by a 
signal. A process may register a SIGTERM handler to ensure that the file is 
deleted, but SIGKILL cannot be handled. Windows: the file will be deleted when 
it is closed, even if the process is terminated.

Note that for Windows it is possible to make the file permanent, but it's 
probably not common enough to bother with documenting this. Currently the 
documentation states that "[w]hether the name can be used to open the file a 
second time, while the named temporary file is still open, varies across 
platforms (it can be so used on Unix; it cannot on Windows NT or later)". 
Actually on Windows the file can be opened again while the named temporary file 
is still open. You can use an opener that calls os.open with the O_TEMPORARY 
flag. But the opener can also call _winapi.CreateFile with read, write, and 
delete sharing. If DELETE access is requested this handle can be used to make 
the file permanent via SetFileInformationByHandle.

--
assignee:  -> docs@python
components: +Documentation
nosy: +docs@python, eryksun
versions: +Python 3.5, Python 3.6 -Python 3.1, Python 3.2

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26385] the call of tempfile.NamedTemporaryFile fails and leaves a file on the disk

2016-02-20 Thread SilentGhost

SilentGhost added the comment:

Here is the updated patch including fixes for except and order of deletion.

--
Added file: http://bugs.python.org/file41979/issue26385_3.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: I can't install python on my pc

2016-02-20 Thread Mark Lawrence

On 20/02/2016 07:34, Giriprasadh Raghavan wrote:


I can’t install python on my pc because it encounters an error every time I try 
to install it. Please help as soon as possible.
Sent from Mail for Windows 10



Asked and answered repeatedly over the last few months, so please search 
the archives for the answer to your specific situation, whatever that 
may be.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


I can't install python on my pc

2016-02-20 Thread Giriprasadh Raghavan

I can’t install python on my pc because it encounters an error every time I try 
to install it. Please help as soon as possible.
Sent from Mail for Windows 10

-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26385] the call of tempfile.NamedTemporaryFile fails and leaves a file on the disk

2016-02-20 Thread Eryk Sun

Eryk Sun added the comment:

> By your explanation, it sounds like it would be better 
> to call unlink() before close().

Sorry, I was responding in general, because I thought you meant unlink would 
fail like it would for most open files on Windows, because the CRT normally 
doesn't open files with delete sharing. But I see what you meant now. Yes, the 
order needs to be reversed as unlink() and then close() for this to work. Doing 
the close first does raise a FileNotFoundError.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: asyncio - run coroutine in the background

2016-02-20 Thread Kevin Conway
> getaddrinfo is a notorious pain but I think it's just a library issue; an
async version should be possible in principle.  How does Twisted handle
it?  Does it have a version?

I think we're a little outside the scope of OP's question at this point,
but for the sake of answering this:

There are a few cases that I know of where Twisted uses the standard lib
socket DNS methods. One is when resolving names to IPv6 addresses [1] when
creating a client connection to a remote source. The other is in the
default DNS resolver that is installed in the reactor [2]. Creating client
connections allows the call to 'getaddrinfo' to block without mitigation.
The default DNS resolver, unfortunately, dispatches calls of
'gethostbyname' to a thread pool.

Without seeing the commit history, I'd assume the use of 'socket' and
threads by default is an artifact that predates the implementation of the
DNS protocol in Twisted. Twisted has, in 'twisted.names' [3], a DNS
protocol that uses UDP and leverages the reactor appropriately. Thankfully,
Twisted has a reactor method called 'installResolver' [4] that allows you
to hook in any DNS resolver implementation you want so you aren't stuck
using the default, threaded implementation.

As far as asyncio, it also defaults to an implementation that delegates to
an executor (default: threadpool). Unlike Twisted, though, it appears to
require a subclass of the event loop to override the 'getaddrinfo' method
[5].

[1]
https://github.com/twisted/twisted/blob/trunk/twisted/internet/tcp.py#L622
[2]
https://github.com/twisted/twisted/blob/trunk/twisted/internet/base.py#L257
[3] https://github.com/twisted/twisted/tree/trunk/twisted/names
[4]
https://github.com/twisted/twisted/blob/trunk/twisted/internet/base.py#L509
[5]
https://github.com/python/cpython/blob/master/Lib/asyncio/base_events.py#L572

On Sat, Feb 20, 2016, 03:31 Marko Rauhamaa  wrote:

> Paul Rubin :
>
> > I've just felt depressed whenever I've looked at any Python async
> > stuff. I've written many Python programs with threads and not gotten
> > into the trouble that people keep warning about.
>
> Programming-model-wise, asyncio is virtually identical with threads. In
> each, I dislike the implicit state concept. I want the state to stand
> out with big block letters.
>
> > I've just felt depressed whenever I've looked at any Python async
> > stuff. I've written many Python programs with threads and not gotten
> > into the trouble that people keep warning about. But I haven't really
> > understood the warnings, so maybe they know something I don't. I just
> > write in a multiprocessing style, with every mutable object owned by
> > exactly one thread and accessed only by RPC through queues, sort of a
> > poor man's Erlang. There's a performance hit but there's a much bigger
> > one from using Python in the first place, so I just live with it.
>
> Good for you if you have been able to choose your own programming model.
> Most people have to deal with a legacy mess. Also, maintainers who
> inherit your tidy code might not be careful to ship only nonmutable
> objects in the queues.
>
> Your way of using threads works, of course, with the caveat that it is
> not possible to get rid of a blocking thread from the outside. With
> asyncio, you can at least cancel tasks.
>
>
> Marko
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extending PATH on Windows?

2016-02-20 Thread eryk sun
On Fri, Feb 19, 2016 at 6:57 PM, Dennis Lee Bieber
 wrote:
>
> Problem -- if the OP's PATH had contained the location of the add2path
> script, the OP might not have needed to search for it... (presuming their
> configuration also was set up to treat .py files as executable, entering
> win_add2path would be all that was needed to run it on a command line)

Ulli didn't need to run the file, but to read it as example code.

> "where" only searches the locations defined in PATH

I made it clear in several examples that where.exe is not limited to
searching PATH.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26392] socketserver.BaseServer.close_server should stop serve_forever

2016-02-20 Thread Aviv Palivoda

Aviv Palivoda added the comment:

I see your point about the server_close purpose and I changed the patch to 
simulate the behavior of closed file (raising ValueError when operating on 
closed file).
I don't think that this should be an enhancement as what i try to do is return 
the behavior as it was before the change to the selectors module. When closing 
the socket using server_close at the next serve_forever loop you would have 
gotten ValueError for bad file descriptor to select. In the current 
implementation we actually keep on pulling on a already free resource.
I know that the user should call shutdown before the server_close but i think 
that as you said the behavior should simulate closed file. When someone will 
try to use any other function of a closed file he will receive a ValueError.

--
Added file: 
http://bugs.python.org/file41978/socketserver_close_stop_serve_forever2.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: asyncio - run coroutine in the background

2016-02-20 Thread Marko Rauhamaa
Paul Rubin :

> I've just felt depressed whenever I've looked at any Python async
> stuff. I've written many Python programs with threads and not gotten
> into the trouble that people keep warning about.

Programming-model-wise, asyncio is virtually identical with threads. In
each, I dislike the implicit state concept. I want the state to stand
out with big block letters.

> I've just felt depressed whenever I've looked at any Python async
> stuff. I've written many Python programs with threads and not gotten
> into the trouble that people keep warning about. But I haven't really
> understood the warnings, so maybe they know something I don't. I just
> write in a multiprocessing style, with every mutable object owned by
> exactly one thread and accessed only by RPC through queues, sort of a
> poor man's Erlang. There's a performance hit but there's a much bigger
> one from using Python in the first place, so I just live with it.

Good for you if you have been able to choose your own programming model.
Most people have to deal with a legacy mess. Also, maintainers who
inherit your tidy code might not be careful to ship only nonmutable
objects in the queues.

Your way of using threads works, of course, with the caveat that it is
not possible to get rid of a blocking thread from the outside. With
asyncio, you can at least cancel tasks.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How the heck does async/await work in Python 3.5

2016-02-20 Thread Ian Kelly
On Sat, Feb 20, 2016 at 1:49 AM, Chris Angelico  wrote:
> Actually, that mightn't be a bad thing. Maybe raise that as a tracker
> issue? I just tested, and slapping "from __future__ import
> generator_stop" at the top of Lib/asyncio/futures.py causes your
> example to raise an exception instead of returning None, and doesn't
> seem to break the test suite.

I added your suggestion to the existing http://bugs.python.org/issue26221.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Problem with matplotlib

2016-02-20 Thread Dave Farrance
Dave Farrance  wrote:

>It occurs to me now that the trackback might misidentify the module in
>use, if say, you'd named a file "numbers.py" then got rid of it later
>leaving a "numbers.pyc" somewhere. If so, see where it is:
>
>import numbers
>print numbers.__file__

I seem to have "numbers" on the brain. Replace with "decimal", of
course.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26221] awaiting asyncio.Future swallows StopIteration

2016-02-20 Thread Ian Kelly

Ian Kelly added the comment:

Chris Angelico suggested on python-list that another possibly useful thing to 
do would be to add a "from __future__ import generator_stop" to 
asyncio/futures.py. This would at least have the effect of causing "await 
future" to raise a RuntimeError instead of silently returning None if a 
StopIteration is set on the future. Future.__iter__ is the only generator in 
the file, so this change shouldn't have any other effects.

--
title: asynco run_in_executor swallows StopIteration -> awaiting asyncio.Future 
swallows StopIteration

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: How the heck does async/await work in Python 3.5

2016-02-20 Thread Ian Kelly
On Sat, Feb 20, 2016 at 1:49 AM, Chris Angelico  wrote:
> Definitely seems like it should be fixed, then; the current behaviour
> is that Future.result() raises RuntimeError if you raise
> StopIteration, so having await do the same would make sense.

Future.result() itself simply raises the StopIteration. If you call it
inside a coroutine (which seems odd -- why not await it?) then it's
the coroutine that reraises the StopIteration as RuntimeError. The
__future__ import doesn't even seem to be needed in this case.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: asyncio - run coroutine in the background

2016-02-20 Thread Chris Angelico
On Sat, Feb 20, 2016 at 7:59 PM, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> In a (non-Python) program of mine, I got annoyed by synchronous name
>> lookups, so I hacked around it: instead of using the regular library
>> functions, I just do a DNS lookup directly (which can then be
>> event-based - send a UDP packet, get notified when a UDP packet
>> arrives). Downside: Ignores /etc/nsswitch.conf and /etc/hosts, and
>> goes straight to the name server. Upside: Is able to do its own
>> caching, since the DNS library gives me the TTLs, but
>> gethostbyname/getaddrinfo won't.
>
> Ditto in a Python program of mine, although I don't bother with caching:
> the DNS server is perfectly capable of caching the entries for me.

If you know you have a local DNS server, sure. Mine is written for a
generic situation where that can't be depended on, so it caches
itself. But it's no big deal.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: asyncio - run coroutine in the background

2016-02-20 Thread Marko Rauhamaa
Chris Angelico :

> In a (non-Python) program of mine, I got annoyed by synchronous name
> lookups, so I hacked around it: instead of using the regular library
> functions, I just do a DNS lookup directly (which can then be
> event-based - send a UDP packet, get notified when a UDP packet
> arrives). Downside: Ignores /etc/nsswitch.conf and /etc/hosts, and
> goes straight to the name server. Upside: Is able to do its own
> caching, since the DNS library gives me the TTLs, but
> gethostbyname/getaddrinfo won't.

Ditto in a Python program of mine, although I don't bother with caching:
the DNS server is perfectly capable of caching the entries for me.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: asyncio - run coroutine in the background

2016-02-20 Thread Chris Angelico
On Sat, Feb 20, 2016 at 7:37 PM, Paul Rubin  wrote:
> getaddrinfo is a notorious pain but I think it's just a library issue;
> an async version should be possible in principle.  How does Twisted
> handle it?  Does it have a version?

In a (non-Python) program of mine, I got annoyed by synchronous name
lookups, so I hacked around it: instead of using the regular library
functions, I just do a DNS lookup directly (which can then be
event-based - send a UDP packet, get notified when a UDP packet
arrives). Downside: Ignores /etc/nsswitch.conf and /etc/hosts, and
goes straight to the name server. Upside: Is able to do its own
caching, since the DNS library gives me the TTLs, but
gethostbyname/getaddrinfo won't.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Problem with matplotlib

2016-02-20 Thread Dave Farrance
It occurs to me now that the trackback might misidentify the module in
use, if say, you'd named a file "numbers.py" then got rid of it later
leaving a "numbers.pyc" somewhere. If so, see where it is:

import numbers
print numbers.__file__
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How the heck does async/await work in Python 3.5

2016-02-20 Thread Chris Angelico
On Sat, Feb 20, 2016 at 7:14 PM, Ian Kelly  wrote:
> On Sat, Feb 20, 2016 at 12:57 AM, Chris Angelico  wrote:
>> On Sat, Feb 20, 2016 at 6:48 PM, Ian Kelly  wrote:
>>> As another point that happens to be fresh in my mind, awaiting a
>>> Future on which an exception gets set is supposed to propagate the
>>> exception. I recently found that this breaks if the exception in
>>> question happens to be StopIteration (granted not one that should
>>> generally be allowed to propagate anyway, but that's a separate
>>> discussion) for the simple reason that raising StopIteration in a
>>> generator is equivalent to returning None.
>>
>> Solved by PEP 479. Use "from __future__ import generator_stop" to save
>> yourself the pain.
>
> Nope.
>
> py> from __future__ import generator_stop
> py> import asyncio
> py> async def test_coro():
> ... fut = asyncio.Future()
> ... fut.set_exception(StopIteration())
> ... print('received %r' % await fut)
> ...
> py> list(test_coro().__await__())
> received None
> []
>
> I think because __future__ imports are per-file, and
> asyncio.Future.__iter__ is defined in a file outside my control that
> doesn't have the __future__ import.

You need the future directive in the file that defines the function
that raises, so I guess you'd need to apply that to an asyncio call.
The tricky bit here is that it's a backward compatibility change, but
since asyncio is flagged provisional, I suspect the future directive
could be added (anyone who's depending on
set_exception(StopIteration()) to terminate without an exception will
have to change code).

Actually, that mightn't be a bad thing. Maybe raise that as a tracker
issue? I just tested, and slapping "from __future__ import
generator_stop" at the top of Lib/asyncio/futures.py causes your
example to raise an exception instead of returning None, and doesn't
seem to break the test suite.

> I suppose that when the generator_stop behavior becomes standard then
> it will work, but still that will just cause a RuntimeError to
> propagate instead of the desired StopIteration.

That then becomes a pretty minor wart, on par with hash() never
returning -1 (which I came across recently, but only by snooping the
source) - it'll hack it to -2 instead, because -1 is used as an error
signal. In the same way, StopIteration is special-cased as a return
signal (because there needs to be _some_ mechanism for distinguishing
between yield and raise and return; normally, the difference between
"has a value to return" and "has no value to return" is indicated by
raising in the latter case, but now we need even more
distinguishments), it can't actually be raised per se. Since the
exception chains, you can't get confused.

> It's not really that big a deal since there is a code smell to it, but
> it's surprising since intuitively StopIteration should have no special
> meaning to a PEP 492 coroutine (it's not an iterator, wink wink, nudge
> nudge), and the thing being awaited is a Future, which also doesn't
> intuitively look like an iterator. Note that if you just call
> Future.result(), then the exception propagates as expected; it's just
> awaiting it that doesn't work.

Definitely seems like it should be fixed, then; the current behaviour
is that Future.result() raises RuntimeError if you raise
StopIteration, so having await do the same would make sense.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue13354] tcpserver should document non-threaded long-living connections

2016-02-20 Thread Bas Wijnen

Bas Wijnen added the comment:

Thank you for your fast response as well.

I overlooked that paragraph indeed.  It doesn't mention anything about avoiding 
a socket shutdown however.  Keeping a list of requests isn't very useful if all 
the sockets in the list are closed. ;-)

So I would indeed suggest an addition: I would change this paragraph:

These four classes process requests synchronously; each request must be 
completed before the next request can be started. This isn’t suitable if each 
request takes a long time to complete, because it requires a lot of 
computation, or because it returns a lot of data which the client is slow to 
process. The solution is to create a separate process or thread to handle each 
request; the ForkingMixIn and ThreadingMixIn mix-in classes can be used to 
support asynchronous behaviour.

into:

By default, these four classes process requests synchronously; each request 
must be completed before the next request can be started. This isn’t suitable 
if each request takes a long time to complete, because it requires a lot of 
computation, or because it returns a lot of data which the client is slow to 
process, or because the information that should be sent to the client isn't 
available yet when the request is made. One possible solution is to create a 
separate process or thread to handle each request; the ForkingMixIn and 
ThreadingMixIn mix-in classes can be used to support asynchronous behaviour. 
Another option is to store the socket for later use, and disable the shutting 
down of the socket by overriding process_request with an function that only 
calls finish_request, and not shutdown_request. In that case, the socket must 
be shut down by the program when it is done with it.

At the end of the last paragraph you refer to, it should also be mentioned that 
the program must do something to prevent the socket from being shut down.  In 
the description of process_request, it would probably also be useful to add 
that the default implementation (as opposed to *MixIn) calls shutdown_request() 
after finish_request().

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: [newbie] Problem with matplotlib

2016-02-20 Thread Mark Lawrence

On 20/02/2016 07:42, jenswaelk...@gmail.com wrote:

When I use either of the following commands I get an error for which I don't 
have a solution, could someone here help me further?
These are the commands:
import matplotlib.pyplot as plt


Are you certain that this is what you typed?

C:\Users\Mark\Desktop>py -2.7
Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit 
(AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>>

Please have another go.



or

from matplotlib.pyplot import pyplot as plt


The above is incorrect, you are trying to import 'pyplot' from 
'matplotlib.pyplot'.




This is the error I get:
Traceback (most recent call last):
   File "/home/waelkens/matplotlibdemo.py", line 2, in 
 from matplotlib.pyplot import pyplot as plt
   File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 27, in 

 import matplotlib.colorbar
   File "/usr/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 36, in 

 import matplotlib.contour as contour
   File "/usr/lib/python2.7/dist-packages/matplotlib/contour.py", line 17, in 

 import matplotlib.ticker as ticker
   File "/usr/lib/python2.7/dist-packages/matplotlib/ticker.py", line 152, in 

 import decimal
   File "/usr/lib/python2.7/decimal.py", line 3744, in 
 _numbers.Number.register(Decimal)
AttributeError: 'module' object has no attribute 'Number'

thanks in advance
Jens



With this type of problem I'm inclined to throw the last line of the 
traceback, here the 'AttributeError' one, into a search engine and see 
what you come up with.  The hits you get are often enough to help you 
diagnose the problem.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Guido on python3 for beginners

2016-02-20 Thread Larry Hudson via Python-list

On 02/19/2016 06:36 PM, Steven D'Aprano wrote:

On Fri, 19 Feb 2016 02:39 pm, Rustom Mody wrote:


[snip]


But you can't do anything interesting with this language, so it is not
satisfying. On the other hand, here's "Hello World" in another language,
one which is Turing complete so it can do anything Python or C can do:

(=<`#9]~6ZY32Vx/4Rs+0No-)"Fh}|Bcy?`=*z]Kw%oG4UUS0/@-ejc(:'8dc

but the learning curve is steep enough that it will be frustrating rather
than interesting.

https://en.wikipedia.org/wiki/Malbolge



Somewhat OT, but speaking of "Hello World", check out:

http://www2.latech.edu/~acm/HelloWorld.shtml

It's a collection of "Hello World" programs in umpteen languages.
(Well, not really umpteen, but there are a lot of them.)   ;-)

 -=- Larry -=-

--
https://mail.python.org/mailman/listinfo/python-list


Re: asyncio - run coroutine in the background

2016-02-20 Thread Paul Rubin
Marko Rauhamaa  writes:
> It would appear that disk I/O is considered nonblocking at a very deep
> level:
>  * O_NONBLOCK doesn't have an effect
>  * a process waiting for the disk to respond cannot receive a signal
>  * a process waiting for the disk to respond stays in the "ready" state

You can handle those issues with AIO.  It's open(2) that seems to have
no asynchronous analog as far as I can tell.  Actually, looking at the
AIO man pages, it appears that the Linux kernel currently doesn't
support it and it's instead simulated by a userspace library using
threads.  I didn't realize that before.  But AIO is at least specified
by POSIX, and there was some kernel work (io_setup(2) etc.) that may or
may not still be in progress.  It also doesn't have an open(2) analog,
sigh.

> On the networking side, there is also a dangerous blocking operation:
> socket.getaddrinfo() (and friends). As a consequence, socket.bind(),
> socket.connect() may block indefinitely. In fact, even asyncio's
> BaseEventLoop.create_server() and BaseEventLoop.create_sonnection() may
> block indefinitely without yielding.

getaddrinfo is a notorious pain but I think it's just a library issue;
an async version should be possible in principle.  How does Twisted
handle it?  Does it have a version?  

I've just felt depressed whenever I've looked at any Python async stuff.
I've written many Python programs with threads and not gotten into the
trouble that people keep warning about.  But I haven't really understood
the warnings, so maybe they know something I don't.  I just write in a
multiprocessing style, with every mutable object owned by exactly one
thread and accessed only by RPC through queues, sort of a poor man's
Erlang.  There's a performance hit but there's a much bigger one from
using Python in the first place, so I just live with it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Problem with matplotlib

2016-02-20 Thread Dave Farrance
jenswaelk...@gmail.com wrote:

>  File "/usr/lib/python2.7/decimal.py", line 3744, in 
>_numbers.Number.register(Decimal)
>AttributeError: 'module' object has no attribute 'Number'

Your decimal module seems broken. Confirm that in the Python shell:

import numbers
print numbers.Number

I'm guessing you'll get:
AttributeError: 'module' object has no attribute 'Number'

It appears to be the usual decimal module of the current linux system
python 2.7, so a corrupt hard disk?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How the heck does async/await work in Python 3.5

2016-02-20 Thread Ian Kelly
On Sat, Feb 20, 2016 at 12:57 AM, Chris Angelico  wrote:
> On Sat, Feb 20, 2016 at 6:48 PM, Ian Kelly  wrote:
>> As another point that happens to be fresh in my mind, awaiting a
>> Future on which an exception gets set is supposed to propagate the
>> exception. I recently found that this breaks if the exception in
>> question happens to be StopIteration (granted not one that should
>> generally be allowed to propagate anyway, but that's a separate
>> discussion) for the simple reason that raising StopIteration in a
>> generator is equivalent to returning None.
>
> Solved by PEP 479. Use "from __future__ import generator_stop" to save
> yourself the pain.

Nope.

py> from __future__ import generator_stop
py> import asyncio
py> async def test_coro():
... fut = asyncio.Future()
... fut.set_exception(StopIteration())
... print('received %r' % await fut)
...
py> list(test_coro().__await__())
received None
[]

I think because __future__ imports are per-file, and
asyncio.Future.__iter__ is defined in a file outside my control that
doesn't have the __future__ import.

I suppose that when the generator_stop behavior becomes standard then
it will work, but still that will just cause a RuntimeError to
propagate instead of the desired StopIteration.

It's not really that big a deal since there is a code smell to it, but
it's surprising since intuitively StopIteration should have no special
meaning to a PEP 492 coroutine (it's not an iterator, wink wink, nudge
nudge), and the thing being awaited is a Future, which also doesn't
intuitively look like an iterator. Note that if you just call
Future.result(), then the exception propagates as expected; it's just
awaiting it that doesn't work.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: asyncio - run coroutine in the background

2016-02-20 Thread Marko Rauhamaa
Paul Rubin :

> Marko Rauhamaa  writes:
>> "Frank Millman" :
>>> I would love to drive the database asynchronously, but of the three
>>> databases I use, only psycopg2 seems to have asyncio support.
>> Yes, asyncio is at its infancy. There needs to be a moratorium on
>> blocking I/O.
>
> Unfortunately there appears to be no way to open a file in Linux
> without at least potentially blocking (slow disk or whatever). You
> need separate threads or processes to do the right thing.

I have been wondering about the same thing. It would appear that disk
I/O is considered nonblocking at a very deep level:

 * O_NONBLOCK doesn't have an effect

 * a process waiting for the disk to respond cannot receive a signal

 * a process waiting for the disk to respond stays in the "ready" state

Note that

 * most disk I/O operates on a RAM cache that is flushed irregularly

 * memory mapping and swapping make disk I/O and RAM access two sides of
   the same coin

 * page faults can turn any assembly language instruction into a
   blocking disk I/O operation

 * ordinary disks don't provide for much parallelism; processes are
   usually serialized for disk I/O

If the file system happens to be NFS, a networking issue may paralyze
the whole system.

...

On the networking side, there is also a dangerous blocking operation:
socket.getaddrinfo() (and friends). As a consequence, socket.bind(),
socket.connect() may block indefinitely. In fact, even asyncio's
BaseEventLoop.create_server() and BaseEventLoop.create_sonnection() may
block indefinitely without yielding.

SEE ALSO
getaddrinfo_a(3)


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Guido on python3 for beginners

2016-02-20 Thread Steven D'Aprano
On Thu, 18 Feb 2016 07:40 pm, Terry Reedy wrote:

> 8. 2.x has two subtlely different types of classes.  The 2.x docs do not
> document the type of builtin and stdlib classes. I discovered that
> tkinter classes are still old-style in 2.7 when I backported a patch
> from 3.x to 2.7 and it mysteriously did not work. Py 3 wins here.  To
> me, this alone makes 2.x a bad choice for most beginners.

An excellent point!


> 11.  To test is something is text, isinstance s, c), where 'c' is one of
> str, bytes, unicode, basestring, (bytes, unicode), (str, unicode).  +1
> for 3.x.

In Python 3, it should be much rarer to want to test whether something is
unicode or bytes. You can't combine them easily, so you rarely want to
handle them in identical ways.


> 12. 2.7 has two different open' functions, open and io.open.  In 3.x
> these are the same opjects.  I believe there are other 3.x backports
> like this.

There's also codecs.open().





-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How the heck does async/await work in Python 3.5

2016-02-20 Thread Chris Angelico
On Sat, Feb 20, 2016 at 6:48 PM, Ian Kelly  wrote:
> As another point that happens to be fresh in my mind, awaiting a
> Future on which an exception gets set is supposed to propagate the
> exception. I recently found that this breaks if the exception in
> question happens to be StopIteration (granted not one that should
> generally be allowed to propagate anyway, but that's a separate
> discussion) for the simple reason that raising StopIteration in a
> generator is equivalent to returning None.

Solved by PEP 479. Use "from __future__ import generator_stop" to save
yourself the pain.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-20 Thread Steven D'Aprano
On Fri, 19 Feb 2016 10:53 pm, wrong.addres...@gmail.com wrote:

>> See http://nedbatchelder.com/text/python-parsers.html for a list of
>> parsers that can do all sorts for you.  Or the stdlib re module
> 
> I am an engineer, and do not understand most of the terminology used
> there. 

Google, or the search engine of your choice, is your friend.

https://duckduckgo.com/html/

https://startpage.com/eng/?


Wikipedia even more so: Wikipedia has lots of good, useful articles on
computing concepts.

https://en.wikipedia.org/wiki/Category:Computing

And use the search box visible at the top of every page.

Or ask here.



> And do I need something fancy to read a line of numbers? Should it 
> not be built into the language?

In your own words:

"I will have to read data given to me by people, which may not come in nice
formats like CSV"

I trust that you don't expect the language to come with pre-written
functions to read numbers in every imaginable format. If you do, you will
be disappointed -- no language could possible do this.

To answer your question "Do I need something fancy...?", no, of course not,
reading a line of numbers from a text file is easy.

with open("numbers.txt", "r") as f:
for line in f:
numbers = [int(s) for s in split(line)]


will read and convert integer-valued numbers separated by whitespace like:

123 654 9374 1 -45 3625


one line at a time. You can then collate them for later use, or process them
as you go. If they're floating point numbers, change the call to int() to a
call to float().






-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list