Skip to content

Process hangs from big stdin #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MartinXPN opened this issue Mar 25, 2022 · 3 comments · Fixed by #53
Closed

Process hangs from big stdin #50

MartinXPN opened this issue Mar 25, 2022 · 3 comments · Fixed by #53
Labels
bug Something isn't working priority/top

Comments

@MartinXPN
Copy link
Owner

https://profound.academy/armenian-spoj/kVlW3xG5g1Ix6diXJQJT
This problem has big inputs (>1MB) and that freezes the process when passing stdin.
We should debug and fix this issue.

@MartinXPN MartinXPN added bug Something isn't working priority/top labels Mar 25, 2022
@MartinXPN MartinXPN moved this to In Progress in LambdaJudge Mar 25, 2022
@MartinXPN MartinXPN changed the title Process hands from big stdin Process hangs from big stdin Mar 25, 2022
@MartinXPN
Copy link
Owner Author

MartinXPN commented Mar 26, 2022

Tried to do cat input | program but cat is super slow and results in TLE even if the program was actually optimal.

Might need to try using fifo

Even this program results in TLE:

n, m = map(int, input().split())
for i in range(n):
    a = input().split()
    assert len(a) == m

k = int(input())
for i in range(k):
    a = input().split()
    assert len(a) == 2
    print('YES')

@MartinXPN
Copy link
Owner Author

MartinXPN commented Mar 28, 2022

Seems like the issue is with stdout rather than stdin as this program does not hang:

n, m = map(int, input().split())
print('n:', n)
print('m:', m)

for i in range(n):
    a = input().split()
    assert len(a) == m
print('getting queries...')

k = int(input())
for i in range(k):
    a = input().split()
    assert len(a) == 2
    if i == 0:
        print('i:', i, '=>', a)
    if i == k - 1:
        print('i:', i, '=>', a)

https://www.reddit.com/r/Python/comments/1vbie0/subprocesspipe_will_hang_indefinitely_if_stdout/

https://bugs.python.org/issue41586

@MartinXPN
Copy link
Owner Author

MartinXPN commented Mar 28, 2022

We probably need to upgrade the python version to 3.10 to be able to use the feature providing pipesize to subprocess.Popen.
https://docs.python.org/3/library/subprocess.html#popen-constructor

Reference: python/cpython@23c0fb8

When a pipe is full it blocks for writing.
When a pipe is empty it blocks for reading. On processes that are
very fast this can lead to a lot of wasted CPU cycles. On a typical
Linux system the max pipe size is 1024K which is much better.
For high performance-oriented libraries such as xopen it is nice to
be able to set the pipe size.

The workaround without this feature is to use my_popen_process.stdout.fileno() in
conjuction with fcntl and 1031 (value of F_SETPIPE_SZ) to acquire this behavior.

The problem is that AWS team seems to not care about python 3.10 support that much: aws/aws-lambda-base-images#31

@MartinXPN MartinXPN linked a pull request Mar 28, 2022 that will close this issue
Repository owner moved this from In Progress to Done in LambdaJudge Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority/top
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant