-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
85 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env python3 | ||
import os | ||
from subprocess import Popen, PIPE | ||
from fcntl import fcntl, F_GETFL, F_SETFL | ||
from itertools import count | ||
|
||
def set_nonblock(fd): | ||
flags = fcntl(fd, F_GETFL) | ||
flags |= os.O_NONBLOCK | ||
fcntl(fd, F_SETFL, flags) | ||
|
||
p = Popen(['sleep', '30'], stdin=PIPE, stdout=PIPE, stderr=PIPE) | ||
fd = p.stdin.fileno() | ||
|
||
set_nonblock(fd) | ||
|
||
for i in count(): | ||
try: | ||
os.write(fd, b'a') | ||
except BlockingIOError: | ||
i -= 1 | ||
p.kill() | ||
break | ||
|
||
print("pipe write blocked after {} bytes ({} KiB)".format(i, i//1024)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python3 | ||
import os | ||
from pty import openpty | ||
from fcntl import fcntl, F_GETFL, F_SETFL | ||
from itertools import count | ||
|
||
def set_nonblock(fd): | ||
flags = fcntl(fd, F_GETFL) | ||
flags |= os.O_NONBLOCK | ||
fcntl(fd, F_SETFL, flags) | ||
|
||
master, slave = openpty() | ||
|
||
set_nonblock(slave) | ||
|
||
for i in count(): | ||
try: | ||
os.write(slave, b'a') | ||
except BlockingIOError: | ||
i -= 1 | ||
break | ||
|
||
print("pts write blocked after {} bytes ({} KiB)".format(i, i//1024)) |