PEP 3148 ready for pronouncement [ACCEPTED]
Hi I learned about the futures PEP only today. I saw the example on http://code.google.com/p/pythonfutures/ One thing that worries me is that this approach seems to bypass the usual exception handling mechanism of Python. In particular I'm wondering why you have to do things like: if future.exception() is not None: ... This reminds me a lot of how things are done in C but it's not very pythonic. Wouldn't it be possible and nicer to raise the exception -- if there was one inside the asynchronous job -- when the result of the future is accessed? try: print('%r page is %d bytes' % (url, len(future.result()))) except FutureError: print('%r generated an exception: %s' % (url, future.exception())) Best, Titus
On Tue, Jul 13, 2010 at 12:19 AM, Titus von der Malsburg <malsburg@gmail.com> wrote:
This reminds me a lot of how things are done in C but it's not very pythonic. Wouldn't it be possible and nicer to raise the exception -- if there was one inside the asynchronous job -- when the result of the future is accessed?
That's what actually happens, so you can code it either way (either just calling result() and dealing with any exception that was raised, or else checking for a non-None exception value directly). Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
On Tue, Jul 13, 2010 at 12:48:35AM +1000, Nick Coghlan wrote:
On Tue, Jul 13, 2010 at 12:19 AM, Titus von der Malsburg That's what actually happens, so you can code it either way
That's great! None of the examples I found used the pythonic exception style, that's why I assumed that checking the "return value" is the only possibility. Reading the PEP carefully would have helped. :-) Titus
On 13 Jul 2010, at 00:59, Titus von der Malsburg wrote:
On Tue, Jul 13, 2010 at 12:48:35AM +1000, Nick Coghlan wrote:
On Tue, Jul 13, 2010 at 12:19 AM, Titus von der Malsburg That's what actually happens, so you can code it either way
That's great! None of the examples I found used the pythonic exception style, that's why I assumed that checking the "return value" is the only possibility. Reading the PEP carefully would have helped. :-)
I'd add that it would feel more natural to me to write: try: print('%r page is %d bytes' % (url, len(future.result()))) - except FutureError: - print('%r generated an exception: %s' % (url, future.exception())) + except FutureError as e: + print('%r generated an exception: %s' % (url, e)) Cheers, Brian
Titus von der Malsburg wrote:
None of the examples I found used the pythonic exception style, that's why I assumed that checking the "return value" is the only possibility. Reading the PEP carefully would have helped. :-)
I had to read the pep fairly carefully before I noticed this too, so perhaps it could be made more prominent. -- Greg
participants (4)
-
Brian Quinlan -
Greg Ewing -
Nick Coghlan -
Titus von der Malsburg