ダウンロードファイルへの補助リモートサーバー

最近の研究では、奥行きモデルのダウンロード速度を行うことは、ネットワークの外にあることも理由遅すぎることがわかりました。だから、小さなプラグインは、ファイルをダウンロードするために補助リモートサーバを使用して、行いました。

あなたは準備する必要があります
、ローカルコンピュータ(Python環境)(TCPインタフェース付き)リモートサーバ
:必要な知識
1、PyQtは基礎
2、TCPの知識
3、QTマルチスレッド知識

PyQtはやるマルチスレッドインタフェース&

あなたはPyQtはを理解していない場合は、参照がマスタに5分です。

ポート番号、ダウンロードリンク、ログ:示されているように、私たちはUIインタフェース、3つの主要な部分を設定します。
ここに画像を挿入説明
コードはを参照することができます:

class Example(QWidget):

    def __init__(self):
        super().__init__()
        self.ok = False
        self.port_default = 0
        self.content_tmp = ''
        self.initUI()
    #UI界面涉及
    def initUI(self):
        #1 说明内容
        self.lbl2 = QLabel(self)
        self.lbl2.setText(
            "1、You should input Port first.\n2、Enter the URL and click the download button\n3、If you have some problem, send email to\n [email protected]")
        self.lbl2.move(30, 10)
        #2 下载区
        #2.1 文本URL
        self.lbl = QLabel(self)
        self.lbl.setText("Url:")
        self.lbl.move(30, 93)
        #2.2 链接URL
        self.file_url = QLineEdit(self)
        self.file_url.move(50, 90)
        self.file_url.setGeometry(50, 90, 250, 23)
        #2.3 下载按钮
        download_button = QPushButton('Download', self)
        download_button.clicked.connect(self.download)
        download_button.move(320, 90)
        #3 端口号按钮
        self.download_button = QPushButton('No Port', self)
        self.download_button.clicked.connect(self.login)
        self.download_button.move(400, 10)
        #4 日志
        self.tmp = QTextEdit(self)
        self.tmp.move(50, 120)
        self.tmp.setGeometry(50, 120, 350, 70)

        #5 标题
        self.setGeometry(300, 300, 500, 200)
        self.setWindowTitle('服务器加速下载器@cloudcver')
        self.show()
    def login(self):
        text, ok = QInputDialog.getText(self, 'Set Port',
                                        'Enter your port:')
        if ok:
            self.port_default = int(text)
            self.download_button.setText(text)
            self.content_tmp = self.content_tmp + "%s:Set port at %s\n"%(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),text)
            self.tmp.setText(self.content_tmp)
            self.ok = True
    def download(self):
        if self.ok:
            self.content_tmp = self.content_tmp + "%s:Send the task to server\n" % (
                time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
            self.tmp.setText(self.content_tmp)
            self.thread = DownloadThread()
            self.thread.set_port_url(self.port_default,self.file_url.text())  # 创建
            self.thread.trigger.connect(self.finish)  # 连接信号
            self.thread.start()  # 开始线程
        else:
            reply = QMessageBox.question(self, 'Message',
                                         "You should set port first", QMessageBox.Yes)
    def finish(self):
        self.content_tmp = self.content_tmp + "%s:Finish!\n" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        self.tmp.setText(self.content_tmp)

インターフェイスは、主にマルチスレッドの内容について話す、言うことではない非常に簡単です!
焦点は、ここを見て!
焦点は、ここを見て!
焦点は、ここを見て!

1は、ダウンロード機能を参照して、[OK]このパラメータは、ポート番号が設定されている表します。初期okがTrueに変更後のポートのボタン入力で、Falseです。
以下はいくつかの方法であることをスレッドクラスを定義して、我々はマルチスレッドDownloadThreadを(打ち上げ2、)、:
2.1 set_port_url()メソッドは、いくつかのパラメータを設定するために、私たち自身の定義です。
2.2実行が親クラスの関数であり、我々はそれを再構築する必要があり、これは実行スレッドに実行される機能です。つまり、この実験の実施を開始した後self.thread.start()関数です。
PyQtは2.3トリガは、我々が作成した信号であり、我々は機能にそれを接続し、実行中の出口を通過した後の信号を実行し、それは打ち上げ後、接続を表す関数を実行することができます。
具体的なコードを見ることができます。

class DownloadThread(QThread):
    trigger = pyqtSignal()

    def __int__(self):
        super(DownloadThread, self).__init__()
    def set_port_url(self,port_default,url):
        self.port_default = port_default
        self.url = url
    def run(self):
		##一会补充!
        # # 循环完毕后发出信号
        # print('1线程运行完了')
        self.trigger.emit()

TCPサービス

公開された139元の記事 ウォン称賛26 ビュー30000 +

おすすめ

転載: blog.csdn.net/CLOUD_J/article/details/104752716