Re: [PATCH v2] perf scripts python: Add Python 3 support to exported-sql-viewer.py

From: Tony Jones
Date: Mon Jan 21 2019 - 02:24:26 EST


On 1/20/19 11:27 AM, Jonathan Corbet wrote:
> On Fri, 18 Jan 2019 16:45:04 -0800
> Tony Jones <tonyj@xxxxxxx> wrote:
>
>> On 1/17/19 1:45 AM, Seeteena Thoufeek wrote:
>>
>>> +if sys.version_info[0] < 3:
>>> + import cPickle
>>> +else:
>>> + import _pickle as cPickle
>>
>> Do you really need this?
>>
>> pickle is already in Python2.
>
> Did you mean in Python3? I would agree that using it is better than
> importing the semi-hidden _pickle module.

No. I meant Python2 :)

pickle in Python2 is the python implementation
cPickle in Python2 is the C implementation.

Read: https://docs.python.org/3.1/whatsnew/3.0.html#library-changes
A common pattern in Python 2.x is to have one version of a module implemented in pure Python, with an optional accelerated version implemented as a C extension; for example, pickle and cPickle. This places the burden of importing the accelerated version and falling back on the pure Python version on each user of these modules. In Python 3.0, the accelerated versions are considered implementation details of the pure Python versions. Users should always import the standard version, which attempts to import the accelerated version and falls back to the pure Python version.

I my patchset "import pickle" was sufficient for Python2 and Python3 The question I suppose is whether this script, for Python2, needs the accelerated C implementation. I decided it didn't.

Tony