简体   繁体   English

为什么 ctrl+c 必须是导致错误的组合(例如 KeyboardInterrupt)?

[英]Why does ctrl+c have to be the combination to cause an error (e.g. KeyboardInterrupt)?

In almost, if not every, programming language, pressing ctrl+c cancels your code.在几乎(如果不是所有)编程语言中,按 ctrl+c 会取消您的代码。 Why does it specifically have to be ctrl+c?为什么一定要ctrl+c? So in other words, what made the developers of programming languages decide that ctrl+c has to be the combination to cancel the code and cause an error?那么换句话说,是什么让编程语言的开发人员决定 ctrl+c 必须是取消代码并导致错误的组合?

It doesn't "have to be" anything, it is a convention formed over a long history: Control-C, "C" for cancel, was I think first used in TOPS-10, a Digital Equipment Corporation (DEC) mainframe operating system used in the late 1960s.它不是“必须是”任何东西,它是由悠久历史形成的约定:Control-C,“C”表示取消,我认为它首先用于 TOPS-10,一个数字设备公司 (DEC) 大型机运行1960 年代后期使用的系统。 The control key itself goes back much further, used on telegraphs and teletypewriters to key in non-printing characters.控制键本身可以追溯到更远的地方,在电报机和电传打字机上用于键入非打印字符。 The idea of non-printing characters controlling a machine without sending a message has an even longer history, including procedure signs in Morse code, "NUL" and "DEL" in Baudot code, and other late 19th-century teleprinter standards and their devices.非打印字符在不发送消息的情况下控制机器的想法具有更长的历史,包括摩尔斯电码中的程序标志、鲍多码中的“NUL”和“DEL”,以及其他 19 世纪后期的电传打印机标准及其设备。

Ctrl+C is not a programming language thing. Ctrl+C 不是编程语言。 It is an "interrupt" signal sent to the process executing.它是发送给正在执行的进程的“中断”信号。

Ctrl + C is an interrupt sent manually. Ctrl + C是手动发送的中断。 You can do it programatically using signal.SIGINT :您可以使用signal.SIGINT以编程方式执行此操作:

process = subprocess.Popen(..)
process.send_signal(signal.SIGINT)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我无法在 VS Code 的外部终端中捕获 ctrl+C 键(python 的 KeyBoardInterrupt 异常)? - Why cannot I capture the ctrl+C key (KeyBoardInterrupt exception of python) in external terminal of VS Code? 如何在不调用 KeyboardInterrupt 的情况下按顺序按 ctrl+c 停止代码执行? - How can I stop code execution by sequentially pressing ctrl+c without calling KeyboardInterrupt? 为什么分配给空列表(例如 [] = "")不是错误? - Why isn't assigning to an empty list (e.g. [] = "") an error? 为什么python程序不会用Ctlr + d或Ctrl + c中断? - Why does a python program not interrupt with Ctlr+d or Ctrl+c? 切片`a`(例如`a [1:] == a [: - 1]`)是否创建了`a`的副本? - Does Slicing `a` (e.g. `a[1:] == a[:-1]`) create copies of the `a`? Python:必须按ctrl + c才能得到结果 - Python: Have to press ctrl+c to get an result 为什么我的多线程应用程序的主线程对Ctrl + C没有响应? - Why is the main thread of my multithreaded application unresponsive to Ctrl+C? 关于 python 列表中错误的快速提问 * 常量,例如 [a, b, c, d, e ] * x - Quick question on error in python list * a constant e.g. [a , b, c, d , e ] * x 线程化的Python应用程序对Ctrl + C不起作用 - Threaded Python application does not react on Ctrl+C pynput 不发送 ctrl+c 来复制选定的文本 - pynput does not send ctrl+c to copy selected text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM