process.Process, .refresh() and ValueError

5 views
Skip to first unread message

Floris Bruynooghe

unread,
Jun 15, 2009, 2:04:27 PM6/15/09
to psi-d...@googlegroups.com
Hi

I was wondering about #7 which asks for .kill() .susupend() .resume()
etc. They would need to update the object they've just modified since
all information is effectively static. So maybe it is worth exposing
this completely, by having a .refresh() method too which would allow
you to update the values. This .refresh() methodology would work on
all our objects: arch.ArchBase (in case of a kexec, not that I've ever
seen this but anyway), host.CpuInfo (CPU could go offline,
hotplugging), host.CpuStats, hosts.NetifInfo (hotplugging),
hosts.NefifStats, mount.MountBase (flags, space, even type could
change).

And following on from this it would seem rather weird to get a
ValueError out of any of those process.Process methods for when the
process is gone (which needs to be checked with hash(), not just the
pid). So this leads to wanting a NoSuchProcessError really.


Toughts?

Floris

--
Debian GNU/Linux -- The Power of Freedom
www.debian.org | www.gnu.org | www.kernel.org

Chris Miles

unread,
Jun 24, 2009, 9:15:39 AM6/24/09
to psi-d...@googlegroups.com, Chris Miles

On 16/06/2009, at 4:04 AM, Floris Bruynooghe wrote:

> I was wondering about #7 which asks for .kill() .susupend() .resume()
> etc. They would need to update the object they've just modified since
> all information is effectively static. So maybe it is worth exposing
> this completely, by having a .refresh() method too which would allow
> you to update the values. This .refresh() methodology would work on
> all our objects: arch.ArchBase (in case of a kexec, not that I've ever
> seen this but anyway), host.CpuInfo (CPU could go offline,
> hotplugging), host.CpuStats, hosts.NetifInfo (hotplugging),
> hosts.NefifStats, mount.MountBase (flags, space, even type could
> change).

I agree with the value of a .refresh() method.

>
> And following on from this it would seem rather weird to get a
> ValueError out of any of those process.Process methods for when the
> process is gone (which needs to be checked with hash(), not just the
> pid). So this leads to wanting a NoSuchProcessError really.

Or name the error to more explicitly indicate that an existing process
has since been terminated. ProcessEndedError, ProcessTerminatedError,
ResourceMissingError (a generic error for many/all resource types;
could be a parent exception class for a resource specific error)?
Just some ideas.

Cheers,
Chris

Floris Bruynooghe

unread,
Jun 24, 2009, 5:39:07 PM6/24/09
to psi-d...@googlegroups.com

psi.MissingResourceError
`- psi.process.NoSuchProcessError
`- psi.host.NoSuchDevice
`- psi.mount.NoSuchMount

That could be a sane approch I guess. I'll go for something like
this if no one comes up with better ideas.

Cheers

Chris Miles

unread,
Jun 24, 2009, 7:57:55 PM6/24/09
to psi-d...@googlegroups.com, Chris Miles

On 25/06/2009, at 7:39 AM, Floris Bruynooghe wrote:

>
> On Wed, Jun 24, 2009 at 11:15:39PM +1000, Chris Miles wrote:
>>
>> On 16/06/2009, at 4:04 AM, Floris Bruynooghe wrote:
>>> And following on from this it would seem rather weird to get a
>>> ValueError out of any of those process.Process methods for when the
>>> process is gone (which needs to be checked with hash(), not just the
>>> pid). So this leads to wanting a NoSuchProcessError really.
>>
>> Or name the error to more explicitly indicate that an existing
>> process
>> has since been terminated. ProcessEndedError,
>> ProcessTerminatedError,
>> ResourceMissingError (a generic error for many/all resource types;
>> could be a parent exception class for a resource specific error)?
>> Just some ideas.
>
> psi.MissingResourceError
> `- psi.process.NoSuchProcessError
> `- psi.host.NoSuchDevice
> `- psi.mount.NoSuchMount
>
> That could be a sane approch I guess. I'll go for something like
> this if no one comes up with better ideas.

My only other suggestion is naming the child exceptions with "Missing"
instead of "NoSuch". I like "missing" as it suggests that something
that was there has now disappeared. And is consistent with the parent
exception. So:

psi.MissingResourceError
`- psi.process.MissingProcessError
`- psi.host.MissingDeviceError
`- psi.mount.MissingMountError

If that isn't to people's liking I am happy to settle for Floris'
suggestion.

Cheers
Chris

Floris Bruynooghe

unread,
Jun 25, 2009, 5:06:51 AM6/25/09
to psi-d...@googlegroups.com

But for the case of Process I think it would be too much to have two
different exceptions coming out of the constructor and from the
.refresh(), .kill() etc. methods. And it seems rather odd to have
MissingProcessError out of __init__, while NoSuchProcessError seems
ok in both cases.

That was my motivation to pick this.

Chris Miles

unread,
Jun 25, 2009, 5:21:58 AM6/25/09
to psi-d...@googlegroups.com, Chris Miles

Oh, I see. So you would replace the current "ValueError: No such
process exists." in the constructor with NoSuchProcessError.

Sounds sensible. No real need to too exceptions representing almost
the same thing.

Cheers
Chris

Reply all
Reply to author
Forward
0 new messages