Forum Archive

Why does platform.libc_ver() take more than 25 seconds?

ccc

Open the Pythonista console and type: import platform ; print(platform.libc_ver())

I stumbled into this one while creating platform_info.py

Phuket2

Omg! @ccc, I have been trying to Copy your code from https://github.com/cclauss/Ten-lines-or-less/blob/master/platform_info.py and then just wrap another level around it. Like --
If True:
And paste in your code.

I can't work out what I do wrong. If I paste your code alone, it works. Then as soon as I make a change as to but an outer If True:
It all goes wrong. I fix all the indent issues, then get syntax issues. So frustrating. I wanted to run your timer (contextlib) over the code. It seems like on my device there is no delay. I want to head butt a wall now :)

ccc

I actually made a platform_info() function that returns a dict of name, value pairs but of course that would not fit in ten lines or less so I left it as an exercise for the reader.

Phuket2

Ok, I was just trying to see if on my hardware it took 25seconds to execute. But, I didn't read correctly. You say to do it in the console. I will try in the console

omz

According to the docs, libc_ver parses the interpreter binary in chunks of 2048 bytes, so I guess that takes a while because the Pythonista binary is quite big (around 35 MB). The docs also mention that the function is "probably only usable for executables compiled using gcc", which isn't actually the case for Pythonista (it's compiled with llvm/clang). Fwiw, the function doesn't produce anything useful on a Mac either.

Phuket2

@ccc when I run your code, I get almost immediate response with the below output.

     architecture() = ('32bit', '')
          mac_ver() = ('8.4', ('', '', ''), 'iPad5,4')
          machine() = iPad5,4
             node() = Ians-iPad
         platform() = Darwin-14.0.0-iPad5,4-32bit
     python_build() = ('default', 'Jun 13 2014 12:49:10')
  python_compiler() = GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)

python_implementation() = CPython
python_version() = 2.7.5
python_version_tuple() = ('2', '7', '5')
release() = 14.0.0
system() = Darwin
uname() = ('Darwin', 'Ians-iPad', '14.0.0', 'Darwin Kernel Version 14.0.0: Wed Jun 24 00:47:42 PDT 2015; root:xnu-2784.30.7~30/RELEASE_ARM64_T7001', 'iPad5,4', '')
version() = Darwin Kernel Version 14.0.0: Wed Jun 24 00:47:42 PDT 2015; root:xnu-2784.30.7~30/RELEASE_ARM64_T7001

ccc

If you remove the middle condition of line four then you will see the slowdown. As OMZ says, this is NOT a showstopper issue. Just something that I stumbled into.

Phuket2

Ok. Above my knowledge anyway :) just giving another platform test. But I guess you mean to take out this check -

    if name[0] != '_' and name != 'libc_ver' and callable(value):

When I comment out this line, it hesitates about 1 sec, not much longer. Seems like a wild difference, either I got the wrong line of code or something special with iPad Air 2

ccc

By remove the middle condition I meant:

# change this line:
    if name[0] != '_' and name != 'libc_ver' and callable(value):
# to this line:
    if name[0] != '_' and callable(value):
Phuket2

Ok, I did as you say. Is still max 1.5 sec before writing to the console begins. As I say, I don't understand it. But the output looks identical. But for sure by removing that condition, there is a delay. But a tiny one