http://docs.python.org/2/c-api/init.html#threads

발번역.. 죄송

 

The Python interpreter is not fully thread-safe.

Python 인터프리터는 완전히 쓰레드에 안전하지 않다.

 

In order to support multi-threaded Python programs, there's a global lock, called the global interpreter lock or GIL, that must be held by the current thread before it can safely access Python objects.

멀티 쓰레드 Python 프로그램을 지원하기 위해서 전역 인터프리터 잠금(GIL)이라고 불리는 전역 잠금(global lock)이 있다. 이것은 현재 쓰레드가 실행되기 전에 열어야 한다. 안전하기 파이썬 객체 접근할 수 있게 해준다.

 

 

Without the lock, even the simplest operations could cause problems in a multi-threaded program:

이 잠금이 없으면 멀티 쓰레드 프로그램에서 단순한 명령에서 조차 문제를 발생할 수 있다:

 

for example, when two threads simultaneously increment the reference count of the same object, the reference count could end up being incremented only once instead of twice.

예를 들어 두 쓰레드가 동시에 같은 객체에 레퍼런스 카운트를 증가할 때, 레퍼런스 카운트 마지막에는 두번 대신 오직 한번만 증가될 수 있다.

 

 

Therefore, the rule exists that only the thread that has acquired the GIL may operate on Python objects or call Python/C API functions.

그러므로, Python 객체들이나 Python/C API 함수들은 GIL을 획득해야 한다는 룰이 존재한다.

 

In order to emulate concurrency of execution, the interpreter regularly tries to switch threads (see sys.setcheckinterval()).

동시 실행을 하기 위해서는, 인터프레터는 정기적으로 쓰레드 변경을 시도한다. (sys.setcheckinterval() 를 확인해라).

 

The lock is also released around potentially blocking I/O operations like reading or writing a file, so that other Python threads can run in the meantime.

다른 Python 쓰레드들이 그동안 실행되기 위해서 파일의 읽기 또는 쓰기와 같은 잠재적 I/O 명령들 블로킹 잠금은 또한 해제된다.

 

The Python interpreter keeps some thread-specific bookkeeping information inside a data structure called PyThreadState.

Python 인터프리터는 PyThreadState 라고 불리는 데이터 구조 내에 어떤 특정 쓰레트 부기 정보를 유지한다.

 

There's also one global variable pointing to the current PyThreadState: it can be retrieved using PyThreadState_Get().

 

거기에도 또한 현재 PyThreadState를 가리키는 하나의 전역 변수가 있다. 그것은 PyThreadState_Get()를 통해서 확인할 수 있다.

+ Recent posts