sassoftware / saspy

A Python interface module to the SAS System. It works with Linux, Windows, and Mainframe SAS as well as with SAS in Viya.
https://sassoftware.github.io/saspy
Other
373 stars 150 forks source link

submit() hangs with STDIO on Linux #443

Closed saspyrate closed 2 years ago

saspyrate commented 2 years ago

Describe the bug SASsession.submit(code) works like a charm via IOM on my Windows machine regardless of the length of code. However, as soon as the length of code exceeds approximately 128KB, the command fails on our Linux server when using the STDIO access method.

To reproduce The following is a minimal working example that will hang forever when using STDIO on Linux:

import saspy
LENGTH = 130000

sas = saspy.SASsession()
sas.submit(LENGTH * ";")

Expected behavior The program above terminates in an instant.

Desktop:

Analysis The statement self.stdin.write(pgm) in line 820 of sasiostdio.py seems to be responsible. Apparently the SAS process stops reading from stdin after 128KB of data unless its data from stdout and stderr are processed.

Changing the code in lines 820-940 such that pgm is written in chunks of 127KB to self.stdin and then reading self.stdout and self.stderr fixes the problem.

I didn't create a pull request, since the code of SASsessionSTDIO.submit() is rather sophisticated and I wasn't sure how to change it to comply with the current logic. However, I am happy to create one if it helps.

tomweber-sas commented 2 years ago

Hey @saspyrate thanks for finding this and figuring out what the problem is. I'll look into this and see what I think the simplest fix is. I suspect just integrating a 'chunk'ed submit into the loop for this case where the code is too long, like you've described. That seems like it should be fairly straight forward. Let me play around with it some and see what I see. Thanks! Tom

tomweber-sas commented 2 years ago

Hey @saspyrate, I've pushed a fix for this to main. Want to try it out and see what you think? Thanks, Tom

saspyrate commented 2 years ago

Thanks a lot, Tom! This was very fast. Everything works perfect now.

tomweber-sas commented 2 years ago

Well, it wasn't perfect. Close. But doing it this way messed up the interrupt handling, so I had to address that. Been working on that till now. Just pushed the rest of this. Saw the other issue, but will look at that tomorrow! Thanks, Tom

saspyrate commented 2 years ago

Well, it wasn't perfect. Close. But doing it this way messed up the interrupt handling, so I had to address that. Been working on that till now. Just pushed the rest of this. Saw the other issue, but will look at that tomorrow! Thanks, Tom

Just for your information: I noticed that the interrupt handling doesn't work correctly if SAS isn't running in English. Unfortunately, the keywords "Select" and "Press" are localized.

tomweber-sas commented 2 years ago

Oh, let me look into that (localized keywords). I did have a catchall case in there for if I didn't see those words specifically; should just display what came through and ask for a response. I'll try running in some other language and see what I can find out. Thanks for the heads up!