Threads fixed
This commit is contained in:
parent
8411f08348
commit
04f0aef3df
@ -198,10 +198,7 @@ def file_recv_chunk(file_transfer_handler):
|
|||||||
"""
|
"""
|
||||||
def wrapped(tox, friend_number, file_number, position, chunk, length, user_data):
|
def wrapped(tox, friend_number, file_number, position, chunk, length, user_data):
|
||||||
chunk = chunk[:length] if length else None
|
chunk = chunk[:length] if length else None
|
||||||
if length:
|
execute(file_transfer_handler.incoming_chunk, friend_number, file_number, position, chunk)
|
||||||
execute(file_transfer_handler.incoming_chunk, friend_number, file_number, position, chunk)
|
|
||||||
else:
|
|
||||||
invoke_in_main_thread(file_transfer_handler.incoming_chunk, friend_number, file_number, position, chunk)
|
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
@ -211,10 +208,7 @@ def file_chunk_request(file_transfer_handler):
|
|||||||
Outgoing chunk
|
Outgoing chunk
|
||||||
"""
|
"""
|
||||||
def wrapped(tox, friend_number, file_number, position, size, user_data):
|
def wrapped(tox, friend_number, file_number, position, size, user_data):
|
||||||
if size:
|
invoke_in_main_thread(file_transfer_handler.outgoing_chunk, friend_number, file_number, position, size)
|
||||||
execute(file_transfer_handler.outgoing_chunk, friend_number, file_number, position, size)
|
|
||||||
else:
|
|
||||||
invoke_in_main_thread(file_transfer_handler.outgoing_chunk, friend_number, file_number, position, size)
|
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
@ -3,8 +3,13 @@ import threading
|
|||||||
import queue
|
import queue
|
||||||
from utils import util
|
from utils import util
|
||||||
import time
|
import time
|
||||||
|
from PyQt5 import QtCore
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
# Base threads
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class BaseThread(threading.Thread):
|
class BaseThread(threading.Thread):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -16,6 +21,21 @@ class BaseThread(threading.Thread):
|
|||||||
self.join()
|
self.join()
|
||||||
|
|
||||||
|
|
||||||
|
class BaseQThread(QtCore.QThread):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self._stop_thread = False
|
||||||
|
|
||||||
|
def stop_thread(self):
|
||||||
|
self._stop_thread = True
|
||||||
|
self.wait()
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
# Toxcore threads
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class InitThread(BaseThread):
|
class InitThread(BaseThread):
|
||||||
|
|
||||||
def __init__(self, tox, plugin_loader, settings):
|
def __init__(self, tox, plugin_loader, settings):
|
||||||
@ -53,7 +73,7 @@ class InitThread(BaseThread):
|
|||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
class ToxIterateThread(BaseThread):
|
class ToxIterateThread(BaseQThread):
|
||||||
|
|
||||||
def __init__(self, tox):
|
def __init__(self, tox):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -65,7 +85,7 @@ class ToxIterateThread(BaseThread):
|
|||||||
time.sleep(self._tox.iteration_interval() / 1000)
|
time.sleep(self._tox.iteration_interval() / 1000)
|
||||||
|
|
||||||
|
|
||||||
class ToxAVIterateThread(BaseThread):
|
class ToxAVIterateThread(BaseQThread):
|
||||||
|
|
||||||
def __init__(self, toxav):
|
def __init__(self, toxav):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -77,6 +97,10 @@ class ToxAVIterateThread(BaseThread):
|
|||||||
time.sleep(self._toxav.iteration_interval() / 1000)
|
time.sleep(self._toxav.iteration_interval() / 1000)
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
# File transfers thread
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class FileTransfersThread(BaseThread):
|
class FileTransfersThread(BaseThread):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -115,6 +139,10 @@ def execute(func, *args, **kwargs):
|
|||||||
_thread.execute(func, *args, **kwargs)
|
_thread.execute(func, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
# Invoking in main thread
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class InvokeEvent(QtCore.QEvent):
|
class InvokeEvent(QtCore.QEvent):
|
||||||
EVENT_TYPE = QtCore.QEvent.Type(QtCore.QEvent.registerEventType())
|
EVENT_TYPE = QtCore.QEvent.Type(QtCore.QEvent.registerEventType())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user