The use of sys.exc_info for catching exceptions

2017-02-01 Thread Tiago M. Vieira
Hi, I've came to a problem where I want to keep backwards and forwards compatibility with an exception syntax. And I mean by backwards going further down to Python 2.5. I was pointed to this option from a stack overflow answer[1] that works forward and backwards, I rewrite the solution here:

Catching exceptions from logging socket handler

2015-09-18 Thread Larry Martell
I have a socket logging handler and I want to be able to catch exceptions from it. Specifically, I want to know if the remote side has gone away so I can close the socket and reopen it when the remote side come back. What happens now is that I get Broken pipe and BAD_WRITE_RETRY exceptions, but

Re: Catching exceptions with multi-processing

2015-06-21 Thread Paul Rubin
Fabien fabien.mauss...@gmail.com writes: I am developing a tool which works on individual entities (glaciers) and do a lot of operations on them. There are many tasks to do, one after each other, and each task follows the same interface: ... If most of the resources will be spent on

Re: Catching exceptions with multi-processing

2015-06-20 Thread Fabien
On 06/19/2015 10:58 PM, Chris Angelico wrote: AIUI what he's doing is all the subparts of task1 in parallel, then all the subparts of task2: pool.map(task1, dirs, chunksize=1) pool.map(task2, dirs, chunksize=1) pool.map(task3, dirs, chunksize=1) task1 can be done on all of dirs in parallel, as

Re: Catching exceptions with multi-processing

2015-06-20 Thread Fabien
On 06/20/2015 05:14 AM, Cameron Simpson wrote: I would keep your core logic Pythonic, raise exceptions. But I would wrap each task in something to catch any Exception subclass and report back to the queue. Untested example: def subwrapper(q, callable, *args, **kwargs): try: q.put(

Re: Catching exceptions with multi-processing

2015-06-19 Thread Chris Angelico
On Sat, Jun 20, 2015 at 1:41 AM, Steven D'Aprano st...@pearwood.info wrote: On Sat, 20 Jun 2015 12:01 am, Fabien wrote: Folks, I am developing a tool which works on individual entities (glaciers) and do a lot of operations on them. There are many tasks to do, one after each other, and each

Re: Catching exceptions with multi-processing

2015-06-19 Thread Cameron Simpson
On 19Jun2015 18:16, Fabien fabien.mauss...@gmail.com wrote: On 06/19/2015 04:25 PM, Andres Riancho wrote: My recommendation is that you should pass some extra arguments to the task: * A unique task id * A result multiprocessing.Queue When an exception is raised you put

Catching exceptions with multi-processing

2015-06-19 Thread Fabien
Folks, I am developing a tool which works on individual entities (glaciers) and do a lot of operations on them. There are many tasks to do, one after each other, and each task follows the same interface: def task_1(path_to_glacier_dir): open file1 in path_to_glacier_dir do stuff

Re: Catching exceptions with multi-processing

2015-06-19 Thread Andres Riancho
Fabien, My recommendation is that you should pass some extra arguments to the task: * A unique task id * A result multiprocessing.Queue When an exception is raised you put (unique_id, exception) to the queue. When it succeeds you put (unique_id, None). In the main process you

Re: Catching exceptions with multi-processing

2015-06-19 Thread Oscar Benjamin
On 19 June 2015 at 15:01, Fabien fabien.mauss...@gmail.com wrote: Folks, I am developing a tool which works on individual entities (glaciers) and do a lot of operations on them. There are many tasks to do, one after each other, and each task follows the same interface: def

Re: Catching exceptions with multi-processing

2015-06-19 Thread Jean-Michel Pichavant
- Original Message - From: Oscar Benjamin oscar.j.benja...@gmail.com A simple way to approach this could be something like: #!/usr/bin/env python3 import math import multiprocessing def sqrt(x): if x 0: return 'error', x else: return 'success',

Re: Catching exceptions with multi-processing

2015-06-19 Thread Jean-Michel Pichavant
- Original Message - From: Fabien fabien.mauss...@gmail.com To: python-list@python.org Sent: Friday, 19 June, 2015 4:01:02 PM Subject: Catching exceptions with multi-processing Folks, I am developing a tool which works on individual entities (glaciers) and do a lot

Re: Catching exceptions with multi-processing

2015-06-19 Thread Steven D'Aprano
On Sat, 20 Jun 2015 12:01 am, Fabien wrote: Folks, I am developing a tool which works on individual entities (glaciers) and do a lot of operations on them. There are many tasks to do, one after each other, and each task follows the same interface: I'm afraid your description is

Re: Catching exceptions with multi-processing

2015-06-19 Thread Fabien
On 06/19/2015 05:41 PM, Steven D'Aprano wrote: On Sat, 20 Jun 2015 12:01 am, Fabien wrote: Folks, I am developing a tool which works on individual entities (glaciers) and do a lot of operations on them. There are many tasks to do, one after each other, and each task follows the same

Re: Catching exceptions with multi-processing

2015-06-19 Thread Fabien
On 06/19/2015 04:25 PM, Andres Riancho wrote: Fabien, My recommendation is that you should pass some extra arguments to the task: * A unique task id * A result multiprocessing.Queue When an exception is raised you put (unique_id, exception) to the queue. When it succeeds you

Re: Catching exceptions from Python 2.4 to 3.x

2012-11-17 Thread Steven D'Aprano
On Sat, 17 Nov 2012 14:26:43 +1100, Cameron Simpson wrote: On 17Nov2012 03:12, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: | Is there some other trick to grab the current exception from inside an | except block? sys.exc_info ? Thanks, that is just what I was looking for.

Catching exceptions from Python 2.4 to 3.x

2012-11-16 Thread Steven D'Aprano
Oh for the day I can drop support for Python 2.4 and 2.5... I have some code that needs to run in any version of Python from 2.4 onwards. Yes, it must be a single code base. I wish to catch an exception and bind the exception to a name. In Python 2.6 onwards, I can do: try: something()

Re: Catching exceptions from Python 2.4 to 3.x

2012-11-16 Thread Cameron Simpson
On 17Nov2012 03:12, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: | Oh for the day I can drop support for Python 2.4 and 2.5... | | | I have some code that needs to run in any version of Python from 2.4 | onwards. Yes, it must be a single code base. | | I wish to catch an

defining, raising and catching exceptions

2010-08-05 Thread Chris Hare
I have a block of test code, where I am trying to raise and catch my own user defined exception class NetActiveError(RuntimeError): def __init__(self,error): self.args = error def a(): try: fh = open(me.txt, r) except Exception as (errno, errText): print

Re: defining, raising and catching exceptions

2010-08-05 Thread Benjamin Kaplan
What makes you think it has to do with user-defined exceptions? try : ...raise Exception(hello) ... except Exception as (errno, errText) : ... print whatever ... Traceback (most recent call last): ValueError: need more than 1 values to unpack An Exception is an object, not a tuple of

Re: defining, raising and catching exceptions

2010-08-05 Thread Chris Hare
okay - but why does the response come back like No such file or directory def b ('n', 'e', 't', ' ', 'a', 'l', 'r', 'e', 'a', 'd', 'y', ' ', 'r', 'u', 'n', 'n', 'i', 'n', 'g') On Aug 5, 2010, at 5:49 PM, Benjamin Kaplan wrote: What makes you think it has to do with user-defined exceptions?

Re: defining, raising and catching exceptions

2010-08-05 Thread MRAB
Chris Hare wrote: okay - but why does the response come back like No such file or directory def b ('n', 'e', 't', ' ', 'a', 'l', 'r', 'e', 'a', 'd', 'y', ' ', 'r', 'u', 'n', 'n', 'i', 'n', 'g') The class Exception saves its arguments in the 'args' instance attribute, and when it prints the

Re: defining, raising and catching exceptions

2010-08-05 Thread Chris Hare
On Aug 5, 2010, at 7:37 PM, MRAB wrote: Chris Hare wrote: okay - but why does the response come back like No such file or directory def b ('n', 'e', 't', ' ', 'a', 'l', 'r', 'e', 'a', 'd', 'y', ' ', 'r', 'u', 'n', 'n', 'i', 'n', 'g') The class Exception saves its arguments in the 'args'

Re: defining, raising and catching exceptions

2010-08-05 Thread Steven D'Aprano
On Fri, 06 Aug 2010 01:37:17 +0100, MRAB wrote: The correct way to create your own exceptions is to call the superclass's __init__ method: class NetActiveError(RuntimeError): ... def __init__(self, error): ... RuntimeError.__init__(self, error) As given, that's pointless

catching exceptions from fortran

2008-09-11 Thread john
. is there an easier way to go about doing this? is there something i'm missing about catching exceptions here? Thanks in advance! -- http://mail.python.org/mailman/listinfo/python-list

Re: catching exceptions from fortran

2008-09-11 Thread Gabriel Genellina
. basically, what i want to happen is to try to run 'something' with the wrapped fortran code and if that doesn't work (error encountered, etc.) try something else. is there an easier way to go about doing this? is there something i'm missing about catching exceptions here? I'd reorder the code

[issue2371] Patch for catching exceptions that do not inherit from BaseException

2008-03-17 Thread Taek Joo Kim
New submission from Taek Joo Kim [EMAIL PROTECTED]: With this patch it prints warning message for catching exceptions that don't inherit from BaseException when -3 flag is used. -- components: Interpreter Core files: catchexc.patch keywords: patch messages: 63761 nosy: taicki severity

[issue2371] Patch for catching exceptions that do not inherit from BaseException

2008-03-17 Thread Alexander Belopolsky
Alexander Belopolsky [EMAIL PROTECTED] added the comment: This belongs to issue2291. -- nosy: +belopolsky, brett.cannon __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2371 __

[issue2371] Patch for catching exceptions that do not inherit from BaseException

2008-03-17 Thread Guido van Rossum
Guido van Rossum [EMAIL PROTECTED] added the comment: I'll review this once I address issue2291. -- assignee: - gvanrossum nosy: +gvanrossum priority: - normal __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2371

[issue2371] Patch for catching exceptions that do not inherit from BaseException

2008-03-17 Thread Guido van Rossum
Guido van Rossum [EMAIL PROTECTED] added the comment: Thanks! Applied as r61475. -- resolution: - accepted status: open - closed __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2371 __

[issue2371] Patch for catching exceptions that do not inherit from BaseException

2008-03-17 Thread Alexander Belopolsky
Alexander Belopolsky [EMAIL PROTECTED] added the comment: I left the following comment in issue2291 pertaining to this patch: There is also a subtle bug in the issue2371 patch: $ cat x.py try: raise ValueError except ((ValueError,),): pass $ ./python -3 x.py x.py:3:

[issue2371] Patch for catching exceptions that do not inherit from BaseException

2008-03-17 Thread Guido van Rossum
Guido van Rossum [EMAIL PROTECTED] added the comment: Alex, can you please open a separate bug for that? The cross-posting of comments is unhelpful, and the issue was not introduced by this patch. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2371

[issue2371] Patch for catching exceptions that do not inherit from BaseException

2008-03-17 Thread Guido van Rossum
Guido van Rossum [EMAIL PROTECTED] added the comment: I've checked a temporary work-around for that issue and another one in r61478. This now has some false negatives; that's better than false positives IMO. __ Tracker [EMAIL PROTECTED]

[issue2371] Patch for catching exceptions that do not inherit from BaseException

2008-03-17 Thread Alexander Belopolsky
Alexander Belopolsky [EMAIL PROTECTED] added the comment: On Mon, Mar 17, 2008 at 11:09 PM, Guido van Rossum [EMAIL PROTECTED] wrote: Alex, can you please open a separate bug for that? The cross-posting of comments is unhelpful, and the issue was not introduced by this patch. Please see

Re: catching exceptions from an except: block

2007-03-09 Thread Duncan Booth
Gabriel Genellina [EMAIL PROTECTED] wrote: Not the *previous* exception, but the *current* one. You must be inside an except clause to use a bare raise. No, you don't have to be inside an except clause to use a bare raise. A bare 'raise' will re-raise the last exception that was active in

Re: catching exceptions from an except: block

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 04:49:59 -0300, Gerard Flanagan [EMAIL PROTECTED] escribió: Another version: import exceptions As back in time as I could go (Python 1.5), exceptions were available as builtins... def onfailFalse(fn): def inner(*args, **kwargs): try: return

Re: catching exceptions from an except: block

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 05:52:35 -0300, Duncan Booth [EMAIL PROTECTED] escribió: Gabriel Genellina [EMAIL PROTECTED] wrote: Not the *previous* exception, but the *current* one. You must be inside an except clause to use a bare raise. No, you don't have to be inside an except clause to use a

Re: catching exceptions from an except: block

2007-03-09 Thread Gerard Flanagan
On Mar 9, 9:56 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Fri, 09 Mar 2007 04:49:59 -0300, Gerard Flanagan [EMAIL PROTECTED] escribió: Another version: import exceptions As back in time as I could go (Python 1.5), exceptions were available as builtins... I did not know that.

Re: catching exceptions from an except: block

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 07:30:20 -0300, Gerard Flanagan [EMAIL PROTECTED] escribió: There is a serious flaw on this approach, the function can't return any false value (it would be treated as a failure). I was teaching myself decorators more than anything, so it's not thought out to any

Re: catching exceptions from an except: block

2007-03-09 Thread Gerard Flanagan
On Mar 9, 11:57 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Fri, 09 Mar 2007 07:30:20 -0300, Gerard Flanagan [EMAIL PROTECTED] escribió: There is a serious flaw on this approach, the function can't return any false value (it would be treated as a failure). I was teaching myself

Re: catching exceptions from an except: block

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 08:14:18 -0300, Gerard Flanagan [EMAIL PROTECTED] escribió: Mea culpa. Ego te absolvo in nomine Patris Guidii et Filii Python et Spiritus Sancti Computatorium. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list

Re: catching exceptions from an except: block

2007-03-08 Thread Bruno Desthuilliers
MonkeeSage a écrit : On Mar 7, 4:58 pm, Bruno Desthuilliers [EMAIL PROTECTED] wrote: except_retry: # the missing(???) keyword you're after What is 'except_retry'? A totally imaginary statement that would do what the OP is looking for. To the OP, with the loop and the callables you

Re: catching exceptions from an except: block

2007-03-08 Thread Gerard Flanagan
On Mar 7, 7:32 pm, Arnaud Delobelle [EMAIL PROTECTED] wrote: Hi all, Imagine I have three functions a(x), b(x), c(x) that each return something or raise an exception. Imagine I want to define a function that returns a(x) if possible, otherwise b(x), otherwise c(x), otherwise raise CantDoIt.

Re: catching exceptions from an except: block

2007-03-08 Thread Gabriel Genellina
En Thu, 08 Mar 2007 06:17:37 -0300, Gerard Flanagan [EMAIL PROTECTED] escribió: @onfail(False) def a(x): if x == 1: return 'function a succeeded' else: raise I know it's irrelevant, as you use a bare except, but such raise looks a bit ugly... -- Gabriel

Re: worker thread catching exceptions and putting them in queue

2007-03-08 Thread Aahz
In article [EMAIL PROTECTED], Paul Sijben [EMAIL PROTECTED] wrote: in a worker thread setup that communicates via queues is it possible to catch exceptions raised by the worker executed, put them in an object and send them over the queue to another thread where the exception is raised in that

Re: worker thread catching exceptions and putting them in queue

2007-03-08 Thread Gabriel Genellina
En Thu, 08 Mar 2007 13:31:14 -0300, Aahz [EMAIL PROTECTED] escribió: In article [EMAIL PROTECTED], Paul Sijben [EMAIL PROTECTED] wrote: in a worker thread setup that communicates via queues is it possible to catch exceptions raised by the worker executed, put them in an object and send

Re: catching exceptions from an except: block

2007-03-08 Thread Steven D'Aprano
On Thu, 08 Mar 2007 06:31:20 -0300, Gabriel Genellina wrote: En Thu, 08 Mar 2007 06:17:37 -0300, Gerard Flanagan [EMAIL PROTECTED] escribió: @onfail(False) def a(x): if x == 1: return 'function a succeeded' else: raise I know it's irrelevant, as you use a

Re: catching exceptions from an except: block

2007-03-08 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes: I thought raise on its own was supposed to re-raise the previous exception, but I've just tried it in the interactive interpreter and it doesn't work for me. It means you can catch an exception, do stuff with it, and then pass it upward to earlier

Re: catching exceptions from an except: block

2007-03-08 Thread Steven D'Aprano
On Thu, 08 Mar 2007 16:19:27 -0800, Paul Rubin wrote: Steven D'Aprano [EMAIL PROTECTED] writes: I thought raise on its own was supposed to re-raise the previous exception, but I've just tried it in the interactive interpreter and it doesn't work for me. It means you can catch an exception,

Re: catching exceptions from an except: block

2007-03-08 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes: Are you saying it only works as advertised within the except clause of a try...except block? I think that's the idea. It hadn't occurred to me that it could be used any other way, but I don't have the docs in front of me right now, so maybe I missed

Re: catching exceptions from an except: block

2007-03-08 Thread Gabriel Genellina
En Thu, 08 Mar 2007 21:11:54 -0300, Steven D'Aprano [EMAIL PROTECTED] escribió: @onfail(False) def a(x): if x == 1: return 'function a succeeded' else: raise I thought raise on its own was supposed to re-raise the previous exception, but I've just tried it in

Re: catching exceptions from an except: block

2007-03-08 Thread Gerard Flanagan
On Mar 8, 10:31 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Thu, 08 Mar 2007 06:17:37 -0300, Gerard Flanagan [EMAIL PROTECTED] escribió: @onfail(False) def a(x): if x == 1: return 'function a succeeded' else: raise I know it's irrelevant, as you use a

catching exceptions from an except: block

2007-03-07 Thread Arnaud Delobelle
Hi all, Imagine I have three functions a(x), b(x), c(x) that each return something or raise an exception. Imagine I want to define a function that returns a(x) if possible, otherwise b(x), otherwise c(x), otherwise raise CantDoIt. Here are three ways I can think of doing it: -- # This

Re: catching exceptions from an except: block

2007-03-07 Thread Miki
Hello Arnaud, Imagine I have three functions a(x), b(x), c(x) that each return something or raise an exception. Imagine I want to define a function that returns a(x) if possible, otherwise b(x), otherwise c(x), otherwise raise CantDoIt. Exceptions are for error handling, not flow control.

Re: catching exceptions from an except: block

2007-03-07 Thread Arnaud Delobelle
On 7 Mar, 19:26, Miki [EMAIL PROTECTED] wrote: Hello Arnaud, Hi Miki [snip] Exceptions are for error handling, not flow control. Maybe but it's not always that clear cut! As error handling is a form of flow control the two have to meet somewhere. [snip] As a side note, try to avoid catch:,

Re: catching exceptions from an except: block

2007-03-07 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Arnaud Delobelle wrote: # This one only works because a,b,c are functions # Moreover it seems like an abuse of a loop construct to me def rolled_first(x): for f in a, b, c: try: return f(x) except: continue raise

Re: catching exceptions from an except: block

2007-03-07 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Miki wrote: Exceptions are for error handling, not flow control. That's not true, they are *exceptions* not *errors*. They are meant to signal exceptional situations. And at least under the cover it's used in every ``for``-loop because the end condition is signaled by a

Re: catching exceptions from an except: block

2007-03-07 Thread Larry Bates
Arnaud Delobelle wrote: Hi all, Imagine I have three functions a(x), b(x), c(x) that each return something or raise an exception. Imagine I want to define a function that returns a(x) if possible, otherwise b(x), otherwise c(x), otherwise raise CantDoIt. Here are three ways I can think

Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Miki a écrit : Hello Arnaud, Imagine I have three functions a(x), b(x), c(x) that each return something or raise an exception. Imagine I want to define a function that returns a(x) if possible, otherwise b(x), otherwise c(x), otherwise raise CantDoIt. Exceptions are for error handling,

Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Larry Bates a écrit : (snip) def d(x): if isinstance(x, basestring): # # Code here for string # elif isinstance(x, int): # # Code here for int # elif isinstance(x, float): # # Code here for string #

Re: catching exceptions from an except: block

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 19:00:59 -0300, Bruno Desthuilliers [EMAIL PROTECTED] escribió: this kind of cose is exactly what OO polymorphic dispatch is supposed to this kind of cose? Ce genre de chose? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list

Re: catching exceptions from an except: block

2007-03-07 Thread Arnaud Delobelle
On Mar 7, 8:52 pm, Larry Bates [EMAIL PROTECTED] wrote: [snip] Without knowing more about the functions and the variable it is somewhat hard to tell what you are trying to accomplish. If a, b, c are functions that act on x when it is a different type, change to one function that can handle

Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Arnaud Delobelle a écrit : Hi all, Imagine I have three functions a(x), b(x), c(x) that each return something or raise an exception. Imagine I want to define a function that returns a(x) if possible, otherwise b(x), otherwise c(x), otherwise raise CantDoIt. Here are three ways I can

Re: catching exceptions from an except: block

2007-03-07 Thread garrickp
On Mar 7, 2:48 pm, Arnaud Delobelle [EMAIL PROTECTED] wrote: I'm not really thinking about this situation so let me clarify. Here is a simple concrete example, taking the following for the functions a,b,c I mention in my original post. - a=int - b=float - c=complex - x is a string

Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Gabriel Genellina a écrit : En Wed, 07 Mar 2007 19:00:59 -0300, Bruno Desthuilliers [EMAIL PROTECTED] escribió: this kind of cose is exactly what OO polymorphic dispatch is supposed to this kind of cose? sorry s/cose/code/ Ce genre de chose? En quelques sortes, oui, quoique pas

Re: catching exceptions from an except: block

2007-03-07 Thread garrickp
On Mar 7, 3:04 pm, [EMAIL PROTECTED] wrote: On Mar 7, 2:48 pm, Arnaud Delobelle [EMAIL PROTECTED] wrote: I'm not really thinking about this situation so let me clarify. Here is a simple concrete example, taking the following for the functions a,b,c I mention in my original post. -

Re: catching exceptions from an except: block

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 18:48:18 -0300, Arnaud Delobelle [EMAIL PROTECTED] escribió: for f in int, float, complex: try: return f(x) except ValueError: continue raise CantDoIt But if the three things I want to do are not callable objects but chunks of code this

Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Arnaud Delobelle a écrit : On Mar 7, 8:52 pm, Larry Bates [EMAIL PROTECTED] wrote: [snip] Without knowing more about the functions and the variable it is somewhat hard to tell what you are trying to accomplish. If a, b, c are functions that act on x when it is a different type, change to one

Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Gabriel Genellina a écrit : En Wed, 07 Mar 2007 18:48:18 -0300, Arnaud Delobelle [EMAIL PROTECTED] escribió: for f in int, float, complex: try: return f(x) except ValueError: continue raise CantDoIt But if the three things I want to do are not callable objects

Re: catching exceptions from an except: block

2007-03-07 Thread Diez B. Roggisch
Arnaud Delobelle schrieb: On Mar 7, 8:52 pm, Larry Bates [EMAIL PROTECTED] wrote: [snip] Without knowing more about the functions and the variable it is somewhat hard to tell what you are trying to accomplish. If a, b, c are functions that act on x when it is a different type, change to one

Re: catching exceptions from an except: block

2007-03-07 Thread MonkeeSage
On Mar 7, 4:58 pm, Bruno Desthuilliers [EMAIL PROTECTED] wrote: except_retry: # the missing(???) keyword you're after What is 'except_retry'? To the OP, with the loop and the callables you could also break out of the loop when the condition is met and use the else condition to raise the

Re: catching exceptions from an except: block

2007-03-07 Thread Steven D'Aprano
On Wed, 07 Mar 2007 10:32:53 -0800, Arnaud Delobelle wrote: Hi all, Imagine I have three functions a(x), b(x), c(x) that each return something or raise an exception. Imagine I want to define a function that returns a(x) if possible, otherwise b(x), otherwise c(x), otherwise raise

worker thread catching exceptions and putting them in queue

2007-03-05 Thread Paul Sijben
All, in a worker thread setup that communicates via queues is it possible to catch exceptions raised by the worker executed, put them in an object and send them over the queue to another thread where the exception is raised in that scope? considering that an exception is an object I feel it

Re: worker thread catching exceptions and putting them in queue

2007-03-05 Thread Diez B. Roggisch
Paul Sijben wrote: All, in a worker thread setup that communicates via queues is it possible to catch exceptions raised by the worker executed, put them in an object and send them over the queue to another thread where the exception is raised in that scope? considering that an exception

Re: worker thread catching exceptions and putting them in queue

2007-03-05 Thread Stargaming
Paul Sijben schrieb: All, in a worker thread setup that communicates via queues is it possible to catch exceptions raised by the worker executed, put them in an object and send them over the queue to another thread where the exception is raised in that scope? considering that an

Re: worker thread catching exceptions and putting them in queue

2007-03-05 Thread Paul Sijben
Stargaming Diez, thanks very much! Stargaming wrote: Paul Sijben schrieb: All, in a worker thread setup that communicates via queues is it possible to catch exceptions raised by the worker executed, put them in an object and send them over the queue to another thread where the exception

Re: catching exceptions

2006-12-18 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: class Test(object): ... def _setx(self,strvalue): try: self._x = float(strvalue) except ValueError: print 'Warning : could not set x attribute to %s' % strvalue ... I think what you are looking for is: class

catching exceptions

2006-12-16 Thread [EMAIL PROTECTED]
Hi, In the following program, I have a class Test which has a property x. Its setx function gets a string value and converts it into a float and stores into it. class Test(object): def _getx(self): return self._x def _setx(self,strvalue): try: self._x =

Re: catching exceptions

2006-12-16 Thread Amit Khemka
On 16 Dec 2006 03:54:52 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, In the following program, I have a class Test which has a property x. Its setx function gets a string value and converts it into a float and stores into it. class Test(object): def _getx(self): return

Re: catching exceptions

2006-12-16 Thread Steven D'Aprano
On Sat, 16 Dec 2006 03:54:52 -0800, [EMAIL PROTECTED] wrote: Hi, In the following program, I have a class Test which has a property x. Its setx function gets a string value and converts it into a float and stores into it. [snip code] Python isn't Java. Are you sure you need properties? I

Re: catching exceptions

2006-12-16 Thread Steven D'Aprano
On Sat, 16 Dec 2006 17:36:00 +0530, Amit Khemka wrote: If I gather correctly, i guess in case of errors/exceptions in a class function, you want to get the error string. One thing that comes straight to my mind is, in such a case use a return statement in functions with two arguments. for

Re: catching exceptions

2006-12-16 Thread [EMAIL PROTECTED]
Steven D'Aprano wrote: On Sat, 16 Dec 2006 03:54:52 -0800, [EMAIL PROTECTED] wrote: Hi, In the following program, I have a class Test which has a property x. Its setx function gets a string value and converts it into a float and stores into it. [snip code] Python isn't Java. Are you

Re: catching exceptions

2006-12-16 Thread Steven D'Aprano
On Sat, 16 Dec 2006 05:24:28 -0800, [EMAIL PROTECTED] wrote: Hi, In the following program, I have a class Test which has a property x. Its setx function gets a string value and converts it into a float and stores into it. [snip code] Python isn't Java. Are you sure you need properties?

Re: catching exceptions

2006-12-16 Thread Gabriel Genellina
On 16 dic, 10:24, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Python isn't Java. Are you sure you need properties? I do not know Java. But, object.x = value looks much better than object.set_x(value) . Is there any harm in doing it, provided I have to do more than just storing the value.