【鼎革‧革鼎】︰ Raspbian Stretch 《六之 J 》

雖然派生的 GIL

In CPython, the global interpreter lock, or GIL, is a mutex that protects access to Python objects, preventing multiple threads from executing Python bytecodes at once. This lock is necessary mainly because CPython’s memory management is not thread-safe. (However, since the GIL exists, other features have grown to depend on the guarantees that it enforces.)

CPython extensions must be GIL-aware in order to avoid defeating threads. For an explanation, see Global interpreter lock.

The GIL is controversial because it prevents multithreaded CPython programs from taking full advantage of multiprocessor systems in certain situations. Note that potentially blocking or long-running operations, such as I/O, image processing, and NumPy number crunching, happen outside the GIL. Therefore it is only in multithreaded programs that spend a lot of time inside the GIL, interpreting CPython bytecode, that the GIL becomes a bottleneck.

However the GIL can degrade performance even when it is not a bottleneck. Summarizing those slides: The system call overhead is significant, especially on multicore hardware. Two threads calling a function may take twice as much time as a single thread calling the function twice. The GIL can cause I/O-bound threads to be scheduled ahead of CPU-bound threads. And it prevents signals from being delivered.

※ 註

全局解釋器鎖英語:Global Interpreter Lock,縮寫GIL),是電腦程式設計語言解釋器用於同步執行緒的一種機制,它使得任何時刻僅有一個執行緒在執行。常見例子有CPythonJython不使用GIL)與Ruby MRI

 

設計,使之不利於即時 Real Time 程式設計。若講作為學習之工具,那又何妨乎?故此特說介接傑克的

JACK Audio Connection Kit (JACK) Client for Python

This Python module provides bindings for the JACK library.

Documentation:
http://jackclient-python.rtfd.org/
Code:
http://github.com/spatialaudio/jackclient-python/
Python Package Index:
http://pypi.python.org/pypi/JACK-Client/
License:
MIT – see the file LICENSE for details.

Requirements

Python:
Of course, you’ll need Python. Any version where CFFI (see below) is supported should work. If you don’t have Python installed yet, you should get one of the distributions which already include CFFI and NumPy (and many other useful things), e.g. Anaconda or WinPython.
pip/setuptools:

Those are needed for the installation of the Python module and its dependencies. Most systems will have these installed already, but if not, you should install it with your package manager or you can download and install pip and setuptools as described on the pip installation page. If you happen to have pip but not setuptools, use this command:

pip install setuptools --user
CFFI:

The C Foreign Function Interface for Python is used to access the C-API of the JACK library from within Python. It supports CPython 2.6, 2.7, 3.x; and is distributed with PyPy 2.0 beta2 or later. You should install it with your package manager (if it’s not installed already), or you can get it with:

pip install cffi --user
JACK library:
The JACK library must be installed on your system (and CFFI must be able to find it). Again, you should use your package manager to install it. Make sure you install the JACK daemon (called jackd). This will also install the JACK library package. If you don’t have a package manager, you can try one of the binary installers from the JACK download page. If you prefer, you can of course also download the sources and compile everything locally.
NumPy (optional):
NumPy is only needed if you want to access the input and output buffers in the process callback as NumPy arrays. The only place where NumPy is needed is jack.OwnPort.get_array(). If you need NumPy, you should install it with your package manager or use a Python distribution that already includes NumPy (see above). Installing NumPy with pip requires a compiler and several additional libraries and is therefore not recommended for beginners.

 

程式庫也。

一因容易安裝!

pi@raspberrypi:~ $ apt-cache search jack-client
python-jack-client - JACK Audio Connection Kit (JACK) Client for Python
python3-jack-client - JACK Audio Connection Kit (JACK) Client for Python 3
xjadeo - Video player with JACK sync

 

再則還滿好玩的哩?!