我剛剛開始使用pyftpdlib。我想先做的是拿着示例服務器並將其包裝在一個線程中。但如果我運行這個腳本就不會退出:如何停止pyftpdlib FTP服務器?
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
import logging
import threading
class FtpThread(threading.Thread):
def __init__(self, user_list):
self.user_list = user_list
self.killswitch = 0
threading.Thread.__init__(self)
def run(self,*args,**kwargs):
authorizer = DummyAuthorizer()
authorizer.add_user('user', 'bla', '/home/user/git/verteilerCore2/default_basedir/in/1/', perm='elradfmwM')
handler = FTPHandler
handler.authorizer = authorizer
logging.basicConfig(filename='/var/log/verteiler_ftp.log', level=logging.INFO)
handler.banner = "pyftpdlib based ftpd ready."
address = ('', 21)
self.server = FTPServer(address, handler)
self.server.max_cons = 256
self.server.max_cons_per_ip = 5
self.server.serve_forever()
def stop(self):
self.server.close_all()
def main():
ftp_server = FtpThread("")
ftp_server.start()
import time
time.sleep(1)
ftp_server.stop()
if __name__ == '__main__':
main()
我需要做些什麼才能使server_forever停止?呼喚「close_all」從服務停止服務器,但整個腳本不會退出:(
「停止服務器服務」 - 這是否意味着它不會接受任何進一步的請求? – User 2014-10-28 06:44:12
是的。我無法連接,但線程不會退出 – JasonTS 2014-10-28 23:14:00