GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-85984: Add _POSIX_VDISABLE from unistd.h to termios module. by 8vasu · Pull Request #114985 · python/cpython

Conversation

@8vasu

@8vasu 8vasu commented Feb 4, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This follows #102413.

POSIX General Terminal Interface defines Special Control Characters. An example of this is the INTR character, which is usually set to Control-C, which sends the SIGINT signal to interrupt a process running in the terminal.

POSIX General Terminal Interface allows the programmer to disable these characters by setting them to _POSIX_VDISABLE, which is defined in POSIX <unistd.h>. This is how POSIX stty(1) disables special control characters internally; for example, running the following command will disable the INTR character:

stty intr undef

Now hitting Control-C will not send SIGINT to the running process until it is reset using the following command:

stty intr ^c.

At any given point of time, check all terminal settings by running stty -a.

This PR adds _POSIX_VDISABLE to the termios module.

  • Issue: Lib/pty.py major revision #85984

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@8vasu
Add _POSIX_VDISABLE from unistd.h to termios module.
67bd481
Signed-off-by: Soumendra Ganguly <[email protected]>
@bedevere-app bedevere-app Bot added the awaiting review label Feb 4, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Feb 4, 2024
Lib/pty.py major revision #85984
Open
@blurb-it
📜🤖 Added by blurb_it.
60c95d4
@8vasu

8vasu commented Feb 4, 2024

Copy link
Copy Markdown
Contributor Author

@gpshead @encukou

In a previous PR in this series (#101832), I mentioned the idea of writing a Python library that mimics stty(1) to provide a unified, highly convenient, and Pythonic interface to termios and winsize functionalities. While working on this, I noticed the lack _POSIX_VDISABLE in the termios library.

This is not a dependency of the main set of changes of this series in #101833, but since this idea was conceived while working on this issue and since this PR is so small, I did not create a separate issue for this.

I have added a test script as a comment.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

8vasu
8vasu commented Feb 4, 2024
View reviewed changes
Comment thread Modules/termios.c
#ifdef _POSIX_VDISABLE
{"_POSIX_VDISABLE", _POSIX_VDISABLE},
#endif

@8vasu 8vasu Feb 4, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following script uses termios._POSIX_VDISABLE to disable INTR. Then it calls stty(1) to check if INTR has successfully been disabled.

#!/usr/bin/python3

# Written and tested on Debian GNU/Linux 12 (bookworm) using stty (GNU coreutils) 9.1.

import subprocess
import termios

def stty_intr_value():
    out = subprocess.run(['stty', '-a'], stdout=subprocess.PIPE, text=True).stdout
    s = out.replace(";", " ")
    sub = "intr = "
    i = s.find(sub) + len(sub)
    return s[i:].split()[0]

t = termios.tcgetattr(0)
t[6][termios.VINTR] = bytes([termios._POSIX_VDISABLE])
termios.tcsetattr(0, termios.TCSANOW, t)

assert stty_intr_value() == "<undef>"
print("PASSED")

Hit Control-C after running running above script to see SIGINT not being sent.

Please run stty intr ^c to restore Control-C functionality.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@8vasu
Merge branch 'main' into termios_posix_vdisable
299d88e
@8vasu

8vasu commented Feb 10, 2024

Copy link
Copy Markdown
Contributor Author

@gpshead @encukou Just a gentle reminder. No rush at all.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gpshead added 2 commits February 11, 2024 02:03
@gpshead
ReSTify the NEWS entry.
e70e309
@gpshead
fix my news typo.
aa71dc7
@gpshead
gpshead enabled auto-merge (squash) February 11, 2024 10:06
@gpshead gpshead self-assigned this Feb 11, 2024
@gpshead
gpshead merged commit bf75f1b into python:main Feb 11, 2024
@bedevere-app bedevere-app Bot removed the awaiting review label Feb 11, 2024
@8vasu

8vasu commented Feb 12, 2024

Copy link
Copy Markdown
Contributor Author

@gpshead Thank you so much! I will make my stty-like library available soon and send you a link.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull request Feb 14, 2024
@8vasu @gpshead @fsc-eriker
pythongh-85984: Add _POSIX_VDISABLE from unistd.h to termios module. (p…
9d6c9d8
…ython#114985)

Signed-off-by: Soumendra Ganguly <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@gpshead gpshead

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@8vasu @gpshead
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.