Bug 114506 - [ẁebkitpy] Executive.cpu_count() ignores $NUMBER_OF_PROCESSORS
Summary: [ẁebkitpy] Executive.cpu_count() ignores $NUMBER_OF_PROCESSORS
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-12 06:27 PDT by Philippe Normand
Modified: 2013-04-15 04:06 PDT (History)
4 users (show)

See Also:


Attachments
Patch (1.48 KB, patch)
2013-04-12 08:43 PDT, Manuel Rego Casasnovas
no flags Details | Formatted Diff | Diff
Patch (1.52 KB, patch)
2013-04-14 22:40 PDT, Manuel Rego Casasnovas
no flags Details | Formatted Diff | Diff
Patch (1.46 KB, patch)
2013-04-15 03:35 PDT, Manuel Rego Casasnovas
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Normand 2013-04-12 06:27:20 PDT
$NUMBER_OF_PROCESSORS is used in webkitperl, it'd be nice to have support for it in webkitpy too.
Comment 1 Manuel Rego Casasnovas 2013-04-12 08:43:36 PDT
Created attachment 197852 [details]
Patch
Comment 2 Philippe Normand 2013-04-12 08:50:23 PDT
Comment on attachment 197852 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=197852&action=review

> Tools/Scripts/webkitpy/common/system/executive.py:145
> +        if 'NUMBER_OF_PROCESSORS' in os.environ:

This test can be removed. os.environ.get() will return None if the env var is not set, I think.

> Tools/Scripts/webkitpy/common/system/executive.py:150
> +            except:

please explicitely catch ValueError :)
Comment 3 Manuel Rego Casasnovas 2013-04-14 22:40:11 PDT
Created attachment 198023 [details]
Patch

os.environ.get() returns None, but None has type NoneType and if you use it in int() it raises a TypeError exception instead of a ValueError. So, I've kept the if checking that the environment variable is defined and then I've added ValueError in the catch clause.
Comment 4 Philippe Normand 2013-04-14 23:55:43 PDT
(In reply to comment #3)
> Created an attachment (id=198023) [details]
> Patch
> 
> os.environ.get() returns None, but None has type NoneType and if you use it in int() it raises a TypeError exception instead of a ValueError. So, I've kept the if checking that the environment variable is defined and then I've added ValueError in the catch clause.

Well, it's possible to catch multiple exceptions with a single except or even multiple except statements :)
Comment 5 Manuel Rego Casasnovas 2013-04-15 03:35:47 PDT
Created attachment 198048 [details]
Patch
Comment 6 Zan Dobersek 2013-04-15 04:02:50 PDT
(In reply to comment #3)
> Created an attachment (id=198023) [details]
> Patch
> 
> os.environ.get() returns None, but None has type NoneType and if you use it in int() it raises a TypeError exception instead of a ValueError. So, I've kept the if checking that the environment variable is defined and then I've added ValueError in the catch clause.

It's possible to define the default value that's to be returned when the searched item is not present in the dictionary. In this case it would probably be 0.
http://docs.python.org/2/library/stdtypes.html#dict.get

Also, mildly interesting, the ẁ (U+1E81) in the [ẁebkitpy] tag in the title does not get reflected in the changelog.
Comment 7 WebKit Commit Bot 2013-04-15 04:06:53 PDT
Comment on attachment 198048 [details]
Patch

Clearing flags on attachment: 198048

Committed r148429: <http://trac.webkit.org/changeset/148429>
Comment 8 WebKit Commit Bot 2013-04-15 04:06:56 PDT
All reviewed patches have been landed.  Closing bug.