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: imp

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 it

Re: Catching exceptions with multi-processing

2015-06-21 Thread Paul Rubin
Fabien 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 computation and the communication

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-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-19 Thread Cameron Simpson
On 19Jun2015 18:16, Fabien 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 (unique_id, exception) to the queue

Re: Catching exceptions with multi-processing

2015-06-19 Thread Chris Angelico
On Sat, Jun 20, 2015 at 1:41 AM, 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 fol

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 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 inter

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 contrad

Re: Catching exceptions with multi-processing

2015-06-19 Thread Jean-Michel Pichavant
- Original Message - > From: "Oscar Benjamin" > 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', math.sqrt(x) >

Re: Catching exceptions with multi-processing

2015-06-19 Thread Oscar Benjamin
On 19 June 2015 at 15:01, 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: > > def task_1(path_to_glacier_dir): > o

Re: Catching exceptions with multi-processing

2015-06-19 Thread Jean-Michel Pichavant
- Original Message - > From: "Fabien" > 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) >

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 consu

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 i

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 > 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. -- Steven -- http://mail.

Re: Catching exceptions from Python 2.4 to 3.x

2012-11-16 Thread Cameron Simpson
On 17Nov2012 03:12, Steven D'Aprano 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 exception and bind the exception to a name

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() e

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 po

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

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 ex

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 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 o

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: catching exceptions from fortran

2008-09-11 Thread Gabriel Genellina
ould be more specific (both in scope and what it catches). The Exception class is the more generic exception that you should catch. 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

catching exceptions from fortran

2008-09-11 Thread john
'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? Thanks in advance! -- http://mail.python.org/mailman/listinfo/python-list

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-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 te

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 an

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

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

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: >

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 act

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 ir

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

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 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 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 earlie

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 irrelevan

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

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

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: 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

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

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 Can

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 ex

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, chang

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

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, chan

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

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 origin

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, quo

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 i

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

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 hand

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 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 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

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

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

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 > r

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 "c

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.

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 o

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

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 e

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 ex

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 ought

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:

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 val

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 n

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

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. > >

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? >

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): >

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 = float(st