Skip to content

Commit

Permalink
Test pts/pipe bufsize
Browse files Browse the repository at this point in the history
  • Loading branch information
ichizok committed Apr 16, 2024
1 parent 09d6c8f commit fb9135b
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 16 deletions.
53 changes: 37 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,50 @@ on:
default: github actions hello

jobs:
trial-docker-buildx:
runs-on: ubuntu-latest
trial-bufsize:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-13
- macos-14

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Check pipebufsize
run: python3 pipebufsize.py

- name: Preparation
run: |
mkdir -p target
echo hello > target/index.txt
find -type f -not -path './.*/*' | sort
- name: Check ptsbufsize
run: python3 ptsbufsize.py

- name: Build Docker Image
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: "buildtest:latest"
outputs: type=image,oci-mediatypes=true,compression=gzip,compression-level=3,force-compression=true
# trial-docker-buildx:
# runs-on: ubuntu-latest
#
# steps:
# - name: Checkout
# uses: actions/checkout@v4
#
# - name: Setup Docker Buildx
# uses: docker/setup-buildx-action@v3
#
# - name: Preparation
# run: |
# mkdir -p target
# echo hello > target/index.txt
# find -type f -not -path './.*/*' | sort
#
# - name: Build Docker Image
# uses: docker/build-push-action@v5
# with:
# context: .
# push: false
# tags: "buildtest:latest"
# outputs: type=image,oci-mediatypes=true,compression=gzip,compression-level=3,force-compression=true

# trial-multiline:
# runs-on: ubuntu-latest
Expand Down
25 changes: 25 additions & 0 deletions pipebufsize.py
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))
23 changes: 23 additions & 0 deletions ptsbufsize.py
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))

0 comments on commit fb9135b

Please sign in to comment.