Commit 074c6036 authored by ibuler's avatar ibuler

[Update] 继续支持多进程

parent 5b05f664
...@@ -8,19 +8,18 @@ import threading ...@@ -8,19 +8,18 @@ import threading
import time import time
import random import random
import multiprocessing import multiprocessing
from multiprocessing.reduction import recv_handle, send_handle, DupFd from multiprocessing.reduction import recv_handle, send_handle
import paramiko import paramiko
from coco.utils import ssh_key_gen, get_logger from .utils import ssh_key_gen, get_logger
from coco.interface import SSHInterface from .interface import SSHInterface
from coco.interactive import InteractiveServer from .interactive import InteractiveServer
from coco.models import Connection from .models import Connection
from coco.sftp import SFTPServer from .sftp import SFTPServer
from coco.config import config from .config import config
logger = get_logger(__file__) logger = get_logger(__file__)
current_socks = []
BACKLOG = 5 BACKLOG = 5
...@@ -53,7 +52,7 @@ class SSHServer: ...@@ -53,7 +52,7 @@ class SSHServer:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
sock.bind((host, port)) sock.bind((host, port))
sock.listen(BACKLOG) sock.listen(BACKLOG)
while True: while not self.stop_evt.is_set():
try: try:
client, addr = sock.accept() client, addr = sock.accept()
worker = random.choice(workers) worker = random.choice(workers)
...@@ -63,7 +62,7 @@ class SSHServer: ...@@ -63,7 +62,7 @@ class SSHServer:
def start_worker(self, in_p, out_p): def start_worker(self, in_p, out_p):
out_p.close() out_p.close()
while True: while not self.stop_evt.is_set():
fd = recv_handle(in_p) fd = recv_handle(in_p)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, fileno=fd) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, fileno=fd)
# print("Recv sock: {}".format(sock)) # print("Recv sock: {}".format(sock))
...@@ -95,12 +94,10 @@ class SSHServer: ...@@ -95,12 +94,10 @@ class SSHServer:
server_p.join() server_p.join()
c1.close() c1.close()
c2.close() c2.close()
print("Exit") print("Exit ssh server process")
def handle_connection(self, sock, addr): def handle_connection(self, sock, addr):
logger.debug("Handle new connection from: {}".format(addr)) logger.debug("Handle new connection from: {}".format(addr))
time.sleep(4)
print("Sock is closed: {} 2".format(sock._closed))
transport = paramiko.Transport(sock, gss_kex=False) transport = paramiko.Transport(sock, gss_kex=False)
try: try:
transport.load_server_moduli() transport.load_server_moduli()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment