python-eel/Eel

Is it possible to start a thread this way?

Open

#584 geöffnet am 15. Apr. 2022

Auf GitHub ansehen
 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Python (570 Forks)batch import
help wanted

Repository-Metriken

Stars
 (5.980 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

Hello. I have a simple task. I want to upload a file using sftp and display the upload progress. Would this approach be correct?

My JS:

<html>
	<head>
		<script type="text/javascript" src="/eel.js"></script>
		<script type="text/javascript">
	
			eel.expose(set_progress);
			function set_progress(p) {
				document.getElementById("progress").textContent = p;
			}
			
		</script>
	</head>
	<body>
		<span id="progress"></span>
	</body>
</html>

...and Python:

import os
import eel
from paramiko import SSHClient, AutoAddPolicy
import threading

eel.init(os.getcwd())

def upload():
    ssh = SSHClient()
    ssh.set_missing_host_key_policy(AutoAddPolicy())
    ssh.connect(hostname='host', port=22, username='user', password='pass')

    sftp = ssh.open_sftp()

    sftp.put('/path/to/my/file', '/path/on/server/to/file', lambda current, total: eel.set_progress(round(current*100/total)) )

    sftp.close()
    ssh.close()

x = threading.Thread(target=upload)
eel.spawn(x.start())
    
eel.start('index.html', blocking=False)

x.join()

Pay attention to the use of the eel in sftp.put and run thread in eel.spawn. It's correct?

Thank you!

Contributor Guide