Bug assert statement does not work in Kodi-Python?
#16
(2016-09-24, 14:39)Roman_V_M Wrote: What you say maybe true for some other languages like C++ or C# where assert is indeed a purely a debugging tool, but not for Python.

Not a debugging tool in Python? That's exactly what it sounds like... from the Python docs:
Quote:In the current implementation, the built-in variable __debug__ is True under normal circumstances, False when optimization is requested (command line option -O). The current code generator emits no code for an assert statement when optimization is requested at compile time.

Unoptimized code is for development/debugging, optimized code for release (when you are done debugging).

Any developer that puts a run-time dependency on assert in their code needs calling out, and not the Kodi developers.

If you want a debug build of Kodi then build it yourself rather than develop with a release build.
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
Reply
#17
(2016-09-24, 21:10)Milhouse Wrote:
(2016-09-24, 14:39)Roman_V_M Wrote: What you say maybe true for some other languages like C++ or C# where assert is indeed a purely a debugging tool, but not for Python.

Not a debugging tool in Python?

So, not a Pythonista either? *sighs* I guess, it will be hard...

Python has full object introspection at runtime and special hooks for attaching tracing functions to the running code, so it does not need special "debug" mode or debug symbols, like statically compiled languages.

Quote:That's exactly what it sounds like... from the Python docs:
Quote:In the current implementation, the built-in variable __debug__ is True under normal circumstances, False when optimization is requested (command line option -O). The current code generator emits no code for an assert statement when optimization is requested at compile time.

Unoptimized code is for development/debugging, optimized code for release (when you are done debugging).

Sorry, but have I been writing in this topic in Ukrainian? It looks like it, so a short translation for you: in current CPython implementations, both Python 2 and Python 3, optimized mode does not do any real optimization and is used basically never. Kodi is the only example known to me. Moreover, in many Python libraries, including parts of the Standard Library, assert statement is used to check for abnormal conditions at runtime. Like it or not, but it's a fact.

Yes, long time ago in optimized mode some introspection info was stripped out from compiled bytecode to speed up execution, but that time long gone. If you don't believe me, read Guido van Russum's book that I quoted in this topic. Or Guido is not enough authority for you in Python?

Quote:Any developer that puts a run-time dependency on assert in their code needs calling out, and not the Kodi developers.

If you want a debug build of Kodi then build it yourself rather than develop with a release build.

I don't give a... nything about debug or release builds of Kodi. I'm talking about the Python runtime that is built-in in Kodi behaving consistently with all mainstream CPython implementations. That's all.
Reply
#18
(2016-09-25, 14:40)Roman_V_M Wrote: So, not a Pythonista either? *sighs* I guess, it will be hard...

Oh dear.

Regardless of whether you consider me to be a "Pythonista" (if you're a typical example, I'm happy not to be one), the Python developers (who I would posit know far more about the Python language than you) consider assert to be a feature closely related to debugging, and is not something needed in "optimised" code (their language, not mine).
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
Reply
#19
(2016-09-25, 14:40)Roman_V_M Wrote: I don't give a... nything about debug or release builds of Kodi. I'm talking about the Python runtime that is built-in in Kodi behaving consistently with all mainstream CPython implementations. That's all.

And if/when the PYTHONOPTIMIZE=1 setting is removed, you can calm down.
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
Reply
#20
If this comment is still true then disabling PYTHONOPTIMIZE is likely to cause problems for any add-ons or distributions shipping pyo files.
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
Reply
#21
(2016-09-25, 19:53)Milhouse Wrote: If this comment is still true then disabling PYTHONOPTIMIZE is likely to cause problems for any add-ons or distributions shipping pyo files.

Python bytecode files are not "shipped", except for special cases like frozen executables. They are generated in place by a Python interpreter and usually are not compatible even between minor versions.

As for addons shipping .pyo files, read your own rules: http://kodi.wiki/view/Add-on_rules. Pr-compiled files are explicitly forbidden. And in case of Python bytecode they even won't work on different Python versions.
Reply
#22
(2016-09-26, 09:19)Roman_V_M Wrote: Python bytecode files are not "shipped", except for special cases like frozen executables. They are generated in place by a Python interpreter and usually are not compatible even between minor versions.

the problem is that many of our platforms have our shipped python modules(not addons) in read-only filesystems. That means generating pyc(or pyo) in place doesn't work.
Always using plain .py instead of pyc is sub optimal from performance pov, so we precompile the bytecode.
Reply
#23
(2016-09-26, 09:51)wsnipex Wrote:
(2016-09-26, 09:19)Roman_V_M Wrote: Python bytecode files are not "shipped", except for special cases like frozen executables. They are generated in place by a Python interpreter and usually are not compatible even between minor versions.

the problem is that many of our platforms have our shipped python modules(not addons) in read-only filesystems. That means generating pyc(or pyo) in place doesn't work.
Always using plain .py instead of pyc is sub optimal from performance pov, so we precompile the bytecode.

I see. That is a valid point. Though I need to note that currently there is no performance difference at run time (only at load time) between running from bytecode and running from source.
Reply
#24
Sorry for opening up this thread after a while....
i forked kodi and i want that kodi use .pyo if its there, and if not using .py
i don't know how to accomplish this because the newsest kodi does have PYTHONOPTIMIZE = 1 on Darwin so why when i delete al .py files and just let the .pyo files in the folder, does the add-on not open in OSX?
do i have to add any other line somewhere in files


python:
    // Darwin packs .pyo files, we need PYTHONOPTIMIZE on in order to load them.
    // linux built with unified builds only packages the pyo files so need it
#if defined(TARGET_DARWIN) || defined(TARGET_LINUX) || defined(TARGET_ANDROID) || defined(TARGET_WINDOWS)
    setenv("PYTHONOPTIMIZE", "1", 1);
#endif



Question also here
https://stackoverflow.com/questions/4812...yo-like-py
Reply

Logout Mark Read Team Forum Stats Members Help
assert statement does not work in Kodi-Python?0