11.3. Embedded Python Interpreter¶
The embedded Python3 interpreter is a vanilla version of CPython (the
official Python distribution). The Python environment you get in Keypirinha is
pretty similar to the original one except that some modules have been removed
from the standard library:
The exact version number of the application and the interpreter can be read at the beginning of the log in the Console. Or by typing the following commands in the Console window:
>>> import sys >>> sys.version '3.5.0 (default, Oct 18 2015, 16:49:14) [MSC v.1800 64 bit (AMD64)]'
There are some modifications made by Keypirinha that impact the default behavior of Python. All of these modifications are documented in this section.
22.214.171.124. exit() and quit()¶
In its vanilla version, Python offers numerous ways to exit a program. Keypirinha on the other hand is not meant to be shutdown by its plugins and would crash in that case so traps have been installed to avoid that.
As a result, if a plugin calls one of the
_thread.exit(), directly or
NotImplementedError exception is raised instead of the
program being shutdown.
As a side note, may the plugin developer absolutely wishes to crash the application anyway, Python and Keypirinha both offer numerous ways to do that too.
In short: Keypirinha automatically updates the content of the
os.environ map every time an environment variable has been modified
so the plugins always get up-to-date values environment.
Context: Keypirinha has been designed to dynamically adapt as much as possible to any modification made to its running context. That includes the environment variables.
Problem: In the CPython implementation, the
os.environ map is
created at import time and never updated. The
os.getenv() function does
not help here because it is just a wrapper around
os.environ.get(). As a
consequence, a plugin that receives the
EVENTS message (see
keypirinha.Plugin.on_events()) and wants to get the up-to-date value of
an environment variable would not be able to do so easily with the default
Solution: When Keypirinha catches a system notification indicating a
modification to the environment, it updates the environment block associated to
the current process, then eventually refreshes the
This mechanism is totally transparent to the plugins and updated environment
values can be just read the standard way: either by accessing the
os.environ map or by calling