# Python 시그널 핸들러에서 print 호출, 안전할까?

Original title: Is it safe to call print in a Python signal handler?

> Hacker News story 49450248 · language: ko · submitted 2026-08-26
> Web version: https://zeli.app/ko/story/49450248
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 64 · by [hellerve](<https://news.ycombinator.com/user?id=hellerve>) · 💬 35
[original](<https://iafisher.com/2026/08/sigprint>) · [HN discussion](<https://news.ycombinator.com/item?id=49450248>)

## Summary

CPython은 사용자 정의 Python 시그널 핸들러를 C 수준 핸들러 내부에서 직접 호출하지 않아 일반적인 C 시그널 안전 제약에서 벗어나지만, Python 핸들러는 예기치 않게 재진입할 수 있습니다. 이 글은 print 호출 중 재진입이 발생할 때 어떤 일이 일어나는지 스트레스 테스트로 보여주며, 극단적인 상황에서는 RuntimeError로 프로그램이 중단될 수 있음을 밝힙니다. 저자는 실제로 겪을 가능성은 낮지만, 시그널 핸들러에서는 비자명한 작업을 피하라고 조언합니다.

## Key quote

> 극단적인 상황에서 시그널 핸들러에서 print를 호출하면 프로그램이 중단될 수 있습니다.

## HN discussion (35 comments)

### [nine_k](<https://news.ycombinator.com/item?id=49495509>)

> POSIX 시그널은 설계 자체가 망가져 있죠, 아쉽게도: https://lwn.net/Articles/414618/ 파이썬이든 아니든, 시그널 핸들러 안에서 안전한 것은 거의 없습니다.

### [IgorPartola](<https://news.ycombinator.com/item?id=49494869>)

> 정말 재미있는 건 시그널 처리와 스레드를 섞는 건데, 특히 리눅스에서요. 간단한 방법 하나가 있고, 적어도 하나의 함정을 포함하는 방법이 수천 개 있습니다.

### [jrumbut](<https://news.ycombinator.com/item?id=49495668>)

> 저자는 이것의 중요성을 과소평가하는 것 같아요. 예제로 귀결되는 코드를 누군가 쉽게 작성할 수 있다고 상상할 수 있습니다. 시그널이 쏟아지고 print 문 하나만 있으면 되죠. 프로그램이 시그널을 생성한다면, 의도치 않게 시그널이 쏟아질 수도 있습니다. 핸들러에 print 문을 넣으면 이런 결과를 얻을 수 있습니다. 그다지 놀랍지는 않지만, 알아두면 좋습니다.

---

## Cite

- Page: https://zeli.app/ko/story/49450248
- Date: 2026-08-26
- Source: iafisher.com (https://iafisher.com/2026/08/sigprint)
- Hacker News: https://news.ycombinator.com/item?id=49450248

## Other languages

- en: https://zeli.app/story/49450248 · markdown: https://zeli.app/story/49450248.md
- zh: https://zeli.app/zh/story/49450248 · markdown: https://zeli.app/zh/story/49450248.md
- ja: https://zeli.app/ja/story/49450248 · markdown: https://zeli.app/ja/story/49450248.md
- de: https://zeli.app/de/story/49450248 · markdown: https://zeli.app/de/story/49450248.md
- es: https://zeli.app/es/story/49450248 · markdown: https://zeli.app/es/story/49450248.md
- ru: https://zeli.app/ru/story/49450248 · markdown: https://zeli.app/ru/story/49450248.md
