import socket


s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.bind(('', 8080)) # ip, port

s.listen(1)


conn, addr = s.accept()

print 'Connected by', addr

while 1:

    data = conn.recv(1024)

    if not data: break

    conn.send(data)

conn.close()



위처럼 하고 다른서버에서 telnet ip port 로 연결 시도해본다.

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()를 통해서 확인할 수 있다.

"파이썬은 자바 플랫폼에서 실행할 수 있도록 확장되었으며, JVM만 있으면 어디서든 실행할 수 있다는 점이다. 또한 여러 플랫폼을 지원하는 C와 .NET을 위한 파이썬도 있다. 그러니까, 파이썬은 거의 모든 곳에서 실행할 수 있다. 이 책에서는, 파이썬의 우아함과 강력함, 편의성을 갖춘 한편 JVM 상에서 실행할 수 있는 Jython에 초점을 맞추도록 하겠다."

 

http://jythonbook_ko.readthedocs.org/en/latest/LangSyntax.html

 

즉, JVM 상에서 동작하는 python이다. 또한 Jython을 찾아보면서 .net 환경을 위한 IronPython도 있다는 것을 알게 되었다. (http://ironpython.net/ 참고) 꽤 흥미롭다. 발표된 지 2년쯤 된 것 같다. 내가 그 동안 최신 정보에 둔해 알지 못했던 것 같다. 아무튼 이를 이용하면 모든 대부분의 플랫폼에서 우아한 python의 코드를 작성할 수 있게 되고 보다 높은 생산성을 가져다 줄 것이라 기대된다.

+ Recent posts