# WSGI 설정

WSGI를 사용중인 경우 프로세스가 fork된 이후 `hackle_client`를 초기화 해야 합니다.

### uWSGI

```python
# Step 1: uwsgi.ini 설정
enable-threads = True


# Step 2: app.py 설정
from hackle import hackle
from uwsgidecorators import postfork

class HackleClient:
    client = None

    def init(self):
        if self.client is None:
            self.client = hackle.Client(sdk_key='YOUR_SERVER_SDK_KEY')


hackle_client = HackleClient()


# Step 3: post_fork 설정
@postfork
def post_fork(server, worker):
    hackle_client.init()


# Step 4: hackleClient 사용 시
from app import hackle_client

hackle_client.client.variation(...)
```

### gunicorn

```python
# Step 1: app.py 설정
from hackle import hackle

class HackleClient:
    client = None

    def init(self):
        if self.client is None:
            self.client = hackle.Client(sdk_key='YOUR_SERVER_SDK_KEY')


hackle_client = HackleClient()

def post_fork(server, worker):
    hackle_client.init()


# Step 2: gunicorn.conf.py 설정
from app import post_fork

post_fork = post_fork


# Step 3: hackleClient 사용 시
from app import hackle_client

hackle_client.client.variation(...)
```

### gevent 설정

gevent의 몽키패치처럼 내부 통신 방식을 non-blocking 으로 변경하게 되는 경우라면 실제로 호출 시점에 인스턴스가 생성되도록 생성 시점을 지연시켜야 합니다.

```python
# step 1: gevent monkey patch
import gevent.monkey
gevent.monkey.patch_all()

# step 2: app.py wrapper function
from hackle import hackle

def hackle_wrapper():
    if 'client' not in hackle_wrapper.__dict__:
        hackle_wrapper.client = hackle.Client(sdk_key='YOUR_SERVER_SDK_KEY')
    return hackle_wrapper.client

# step 3: hackleClient 사용 시
from app import hackle_wrapper

hackle_wrapper().variation(...)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/development-guide/python/python-sdk-wsgi-init.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
