> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 워커 프로세스에서의 트레이스 데이터 손실

Weave는 애플리케이션 성능에 미치는 영향을 최소화하기 위해 백그라운드 스레드에서 트레이스 데이터를 업로드합니다. 하지만 멀티프로세싱이나 작업 큐 시스템, 또는 Celery 같은 워커 프로세스를 사용하면 트레이스 데이터가 손실될 수 있습니다. 백그라운드 스레드가 트레이스 업로드를 마치기 전에 워커 프로세스가 종료되면 이런 문제가 발생합니다.

워커 프로세스에서 데이터 손실을 방지하려면 워커 작업이 완료되기 전에 `client.flush()` 또는 `client.finish()`를 호출하여 백그라운드 업로드가 끝나도록 하세요. 이 방법은 [AWS Lambda](https://aws.amazon.com/lambda/), [Google Cloud Run](https://cloud.google.com/run) 또는 실행 직후 종료되는 노트북처럼 수명이 짧은 환경에서 특히 유용합니다.

두 메서드는 용도가 다르므로 환경에 맞는 메서드를 선택하세요.

* `weave.flush()`: 별도 출력 없이 플러시를 수행합니다. Weave를 워커 프로세스나 지속적 통합(CI) 환경에 통합한 경우에 권장됩니다.
* `weave.finish()`: 진행률 표시줄이나 상태 callback으로 진행 상황을 알려 줍니다. 대화형 스크립트나 노트북에 권장됩니다.

두 메서드 모두 모든 백그라운드 업로드가 완료될 때까지 블로킹되므로, 워커 프로세스가 종료되어도 트레이스 데이터가 손실되지 않습니다.

다음 예시는 Celery 작업에서 `client.finish()`를 호출하여 워커가 반환되기 전에 트레이스를 플러시하는 방법을 보여 줍니다. `[TEAM-NAME]`은 W\&B 팀 이름으로, `[PROJECT-NAME]`은 W\&B 프로젝트 이름으로 바꾸세요.

```python theme={"system"}
from celery import Celery
import weave

app = Celery('tasks')

@app.task
def process_task(input_data):
    weave.init("[TEAM-NAME]/[PROJECT-NAME]")

    try:
        # 트레이스를 생성하는 작업 로직
        result = your_processing_function(input_data)

        # 작업이 완료되기 전에 모든 트레이스가 업로드되도록 하세요
        weave.finish()

        return result
    finally:
        pass
```

대안으로, `with` 컨텍스트 매니저를 사용하여 종료할 때 `weave.finish()`를 자동으로 호출할 수 있습니다:

```python theme={"system"}
with weave.init("[TEAM-NAME]/[PROJECT-NAME]") as client:
    result = your_processing_function(input_data)

    return result
```

`weave.flush()`로 애플리케이션의 성능을 개선할 수도 있습니다. 자세한 내용은 [플러시](/ko/support/weave/articles/long-eval-clean-up-times)를 참조하세요.

데이터 손실에 대한 복원력을 높이려면 [쓰기 전 로그](/ko/products/wandb/weave/guides/tracking/write-ahead-log)를 활성화하는 것을 고려하세요. 쓰기 전 로그는 트레이스 데이터를 서버로 보내기 전에 디스크에 기록합니다.

***

<Badge stroke shape="pill" color="blue" size="md">[트레이스 데이터](/ko/support/weave/tags/trace-data)</Badge><Badge stroke shape="pill" color="blue" size="md">[Performance](/ko/support/weave/tags/performance)</Badge>
