raise_signal docs imply process receives signal not thread
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Documentation
The documentation of signal.raise_signal(signum) is:
Sends a signal to the calling process
Which somewhat implies the signal is sent to the main thread of the process, ie. equivalent to os.kill(os.getpid(), signum). In actuality the signal is sent to the calling thread, which with the nuance of how Python executes signal handlers can lead to subtly different behaviour with regard to interrupting blocking functions.
The attached example shows how this interpretation can lead to bugs.
$ python example.py kill
Waiting for signal...
Handling signal 15
Wait interrupted by signal
$ python example.py raise_signal
Waiting for signal...
example.py
import os
import signal
import sys
import threading
import time
# Register a handler to flag an event when a signal is received
signalled_flag = threading.Event()
def signal_handler(signum, _frame):
print(f"Handling signal {signum}")
signalled_flag.set()
signal.signal(signal.SIGTERM, signal_handler)
# Raise the signal in a separate thread once the main thread is waiting on said event
def do_raise_signal():
time.sleep(0.01)
signal.raise_signal(signal.SIGTERM)
def do_kill_process():
time.sleep(0.01)
os.kill(os.getpid(), signal.SIGTERM)
match sys.argv:
case [_, "raise_signal"]:
thread = threading.Thread(target=do_raise_signal)
case [_, "kill"]:
thread = threading.Thread(target=do_kill_process)
case _:
print(f"Usage: {sys.argv[0]} [raise_signal|kill]")
sys.exit(1)
thread.start()
# Wait for the signal to be received
print("Waiting for signal...")
signalled_flag.wait()
print("Wait interrupted by signal")
Linked PRs
- gh-129167
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pela entrada da documentação de signal.raise_signal(signum) e leia as orientações vinculadas sobre sinais e threads. Esclareça que o sinal é enviado à thread chamadora, em vez de dar a entender que ele é entregue ao processo ou à thread principal, e depois verifique se a redação e os exemplos da documentação continuam consistentes.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- documentation
- Tipo de issue
- Documentação
- Dificuldade
- 1/5
- Tempo estimado
- Menos de uma hora
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 25/100