Send a signal to subprocess

subproses less.I've tried passing SIGINT through a subprocess for a nonsensical purpose of wanting to run it in a Popen.



```py
from subprocess import Popen
from signal import signal, SIGINT

cmd = '/usr/bin/less /var/log/system.log'.split()
p = Popen(cmd)

def send_signal_fn(signum, frame):
    p.send_signal(SIGINT)

signal(SIGINT, send_signal_fn)
p.communicate() 

Use the signal handler to do `Popen.send_signal (SIGINT)` when SIGINT comes.

Now you can come back from `` `less + F``` without dying.

Recommended Posts

Send a signal to subprocess
I want to send a signal only from the sub thread to the main thread
Send a message from Slack to a Python server
Send a message to LINE with Python (LINE Notify)
A note about subprocess
I want to send a business start email automatically
How to execute a command using subprocess in Python
A quick introduction to pytest-mock
How to install NPI + send a message to line with python
A road to intermediate Python
A super introduction to Linux
Add a dictionary to MeCab
How to call a function
Upload a file to Dropbox
How to hack a terminal
I want to send a message from Python to LINE Bot
Try to select a language
Send a request from AWS Lambda to Amazon Elasticsearch Service
How to send a request to the DMM (FANZA) API with python
How to make a Japanese-English translation
How to write a Python class
How to put a symbolic link
To add a C module to MicroPython ...
Try to draw a Bezier curve
A memo to move Errbot locally
Convert A4 PDF to A3 every 2 pages
Steps to create a Django project
How to make a slack bot
How to create a Conda package
Write standard output to a file
Code to randomly generate a score
How to make a crawler --Advanced
A story addicted to Azure Pipelines
How to make a recursive function
How to create a virtual bridge
Send commands from Atom to Maya
How to make a deadman's switch
How to create a Dockerfile (basic)
[Blender] How to make a Blender plugin
Convert a string to an image
How to delete a Docker container
Metaclass (wip) to generate a dictionary
A light introduction to object detection
5 Ways to Create a Python Chatbot
How to make a crawler --Basic
A tool to convert Juniper config
How to create a config file
[Python] Create API to send Gmail
How to send a visualization image of data created in Python to Typetalk
Send an email to a specific email address with python without SMTP settings
Send mail with mailx to a dummy SMTP server set up with python.
I tried to send a registration completion email from Gmail with django.
Python code to determine the monthly signal of a relative strength investment