Fixed: setting arl and download folder via the GUI

Waiting for a semaphore / subprocess is blocking.  Fix the semaphores
by using tpool (which just runs it in a separate thread in a
non-blocking way).  Swap to a greened subprocess module for opening
download folder.
This commit is contained in:
kermit 2020-09-25 18:04:35 +01:00
parent 224a97bb4b
commit 18db21b61d
2 changed files with 19 additions and 11 deletions

View file

@ -7,7 +7,7 @@ from PyQt5.QtGui import QIcon
import json import json
import webbrowser import webbrowser
from threading import Thread, Lock, Semaphore from threading import Thread, Semaphore
import sys import sys
import os.path as path import os.path as path
from os import makedirs from os import makedirs
@ -16,8 +16,6 @@ from server import run_server
from http.client import HTTPConnection from http.client import HTTPConnection
from deemix.utils.localpaths import getConfigFolder from deemix.utils.localpaths import getConfigFolder
server_lock = Lock()
if sys.platform == "win32": if sys.platform == "win32":
import ctypes import ctypes
myappid = 'RemixDev.deemix' myappid = 'RemixDev.deemix'

View file

@ -2,11 +2,12 @@
import logging import logging
import signal import signal
import sys import sys
import subprocess
from os import path from os import path
import json import json
import eventlet import eventlet
from eventlet import tpool
from eventlet.green import subprocess
requests = eventlet.import_patched('requests') requests = eventlet.import_patched('requests')
urlopen = eventlet.import_patched('urllib.request').urlopen urlopen = eventlet.import_patched('urllib.request').urlopen
@ -404,26 +405,35 @@ def openDownloadsFolder():
@socketio.on('selectDownloadFolder') @socketio.on('selectDownloadFolder')
def selectDownloadFolder(): def selectDownloadFolder():
if gui: if gui:
gui.selectDownloadFolder_trigger.emit() # Must be done with tpool to avoid blocking the greenthread
gui._selectDownloadFolder_semaphore.acquire() result = tpool.execute(doSelectDowloadFolder)
result = gui.downloadFolder
if result: if result:
emit('downloadFolderSelected', result) emit('downloadFolderSelected', result)
else: else:
print("Can't open folder selection, you're not running the gui") print("Can't open folder selection, you're not running the gui")
def doSelectDowloadFolder():
gui.selectDownloadFolder_trigger.emit()
gui._selectDownloadFolder_semaphore.acquire()
return gui.downloadFolder
@socketio.on('applogin') @socketio.on('applogin')
def applogin(): def applogin():
if gui: if gui:
if not session['dz'].logged_in: if not session['dz'].logged_in:
gui.appLogin_trigger.emit() # Must be done with tpool to avoid blocking the greenthread
gui._appLogin_semaphore.acquire() arl = tpool.execute(dologin)
if gui.arl: if arl:
emit('applogin_arl', gui.arl) emit('applogin_arl', arl)
else: else:
emit('logged_in', {'status': 2, 'user': session['dz'].user}) emit('logged_in', {'status': 2, 'user': session['dz'].user})
else: else:
print("Can't open login page, you're not running the gui") print("Can't open login page, you're not running the gui")
def dologin():
gui.appLogin_trigger.emit()
gui._appLogin_semaphore.acquire()
return gui.arl
def run_server(port, host="127.0.0.1", portable=None, mainWindow=None): def run_server(port, host="127.0.0.1", portable=None, mainWindow=None):
global app, gui, arl, is_deezer_available global app, gui, arl, is_deezer_available