Skip to content
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

Deadlock on network disconnect #3

Open
rgreenn opened this issue Apr 13, 2022 · 0 comments
Open

Deadlock on network disconnect #3

rgreenn opened this issue Apr 13, 2022 · 0 comments

Comments

@rgreenn
Copy link

rgreenn commented Apr 13, 2022

First of all, thank you and mstiri for creating p3270 and p5250.

I am trying to automate the execution of various processes using the p5250 module. My goal is to have it run unsupervised, but in testing it seems to get hung up when the network disconnects. I am an amateur at best, so I apologize if any of the following is incorrect and would appreciate your feedback.

Steps to recreate error (during testing I did this in the command line b/c it was the easiest way to disconnect wifi in between commands):
1.) connect to server

from p5250 import P5250Client
my_client = P5250Client(hostName = <hostname string>, path = "/usr/bin/")

if my_client.connect():
    print("Connection successful)"

2.) disconnect wifi

3.) send command
my_client.sendEnter()
At this point it seems to wait indefinitely until I use a keyboardInterrupt.

4.) After using the keyboardInterrupt, I tried sending the Enter command again. This is when it gives the broken pipe error, which I have been trying to handle with something like below (https://www.geeksforgeeks.org/broken-pipe-error-in-python/).

import sys
import errno

try:
	for i in range(4000):
		print(i)
except IOError as e:
	if e.errno == errno.EPIPE:
	pass
	# Handling of the error

After looking further into the code, my thought is that the problem is the use of stdin.write() in the do() function of the S3270 class. The subprocess documentation states the following:

Warning Use communicate() rather than .stdin.write, .stdout.read or .stderr.read to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process.

Is this the cause of the hangup? Would using communicate() fix the issue?

I would appreciate any insight you can offer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant