-
Notifications
You must be signed in to change notification settings - Fork 19
[python] mod_python
dsindex edited this page Jul 25, 2014
·
2 revisions
mod_python
을 이용해서 API를 만들때, 참고용.
- mod_python directives
- multiple interpreters
- sample in httpd.conf
PythonInterpreter init_interpreter
PythonImport some_handler::init init_interpreter
PythonPath "sys.path + ['/data1/webroot/']"
<Directory "/data1/webroot">
AddHandler mod_python .py
PythonOption mod_python.legacy.importer *
PythonHandler request_handler
PythonDebug On
PythonAutoReload On
# SERVICE ENVIRONMENT
PythonPath "sys.path + ['/data1/webroot/']"
</Directory>
-
apache
가 시작될 때 , 예를 들어 prefork 방식인 경우 여러개의 process들이 뜨는데, 각각 python interpreter를 가지고 뜨게 된다. 이것의 이름이 init_interpreter - PythonImport는 some_handler::init 모듈을 단 한번만 import한다.
- /data1/webroot 디렉토리 밑에 .py 확장자 파일은 전부 mod_python의 python interpreter로 구동시킨다
- request가 들어오면 이것은 request_handler가 처리한다.
- apache가 worker 방식으로 구동되는 경우, process당 여러개의 thread들이 동작하게 되는데, request가 들어오면 이런 thread들 중 하나가 request를 처리한다. 그런데, python interpreter 자체가 가지고 있는
GIL(Global Interpreter Lock)
때문에 thread는 한번에 하나씩만 처리될 것이다.