Skip to content

Commit

Permalink
基本完成
Browse files Browse the repository at this point in the history
  • Loading branch information
AresConnor committed Sep 30, 2023
1 parent fae876d commit 118a9f7
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 205 deletions.
21 changes: 17 additions & 4 deletions Clients.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import os
from typing import List
import sqlite3

import requests_cache as rqc

Expand All @@ -9,10 +8,25 @@

curdir = os.path.abspath(os.path.dirname(__file__))


def vacuum():
if os.path.exists(db := os.path.join(curdir, "cache", "CurseForgeBlob-Cache")):
conn = sqlite3.connect(db)
conn.execute("VACUUM")
conn.close()
print("Vacuumed")

if os.path.exists(db := os.path.join(curdir, "cache", "CurseForgeRequest-Cache")):
conn = sqlite3.connect(db)
conn.execute("VACUUM")
conn.close()
print("Vacuumed")


shortCachedRequest = rqc.CachedSession(
os.path.join(curdir, "cache", "CurseForgeRequest-Cache"),
backend="sqlite",
expire_after=300
expire_after=3600
)
longCachedRequest = rqc.CachedSession(
os.path.join(curdir, "cache", "CurseForgeBlob-Cache"),
Expand Down Expand Up @@ -49,4 +63,3 @@
for d in data:
print(d)
print(666)

10 changes: 6 additions & 4 deletions concurrent/future.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def __str__(self):


class Future(QObject):
done = pyqtSignal(object)
childrenDone = pyqtSignal(object)
allDone = pyqtSignal(object) # self
partialDone = pyqtSignal(object) # child future
childrenDone = pyqtSignal(object) # self

def __init__(self):
super().__init__()
Expand All @@ -72,6 +73,7 @@ def __onChildDone(self, childFuture: 'Future') -> None:
if childFuture.isFailed():
self._failed = True
self._counter += 1
self.partialDone.emit(childFuture)
try:
idx = getattr(childFuture, "_idx")
self._result[idx] = childFuture._result
Expand Down Expand Up @@ -113,7 +115,7 @@ def setResult(self, result) -> None:
self.childrenDone.emit(self)
if self._callback:
self._callback(result)
self.done.emit(result)
self.allDone.emit(result)
else:
raise RuntimeError("Future already done")
# self.deleteLater() # delete this future object
Expand All @@ -131,7 +133,7 @@ def setFailed(self, exception: Optional[BaseException]) -> None:
self.childrenDone.emit(self)
if self._failedCallback:
self._failedCallback(self)
self.done.emit(self._result)
self.allDone.emit(self._result)
else:
raise RuntimeError("Future already done")
# self.deleteLater()
Expand Down
8 changes: 6 additions & 2 deletions concurrent/taskManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ def _taskSingleCancel(self, fut: Future):
_id = fut.getTaskID()
task = self.tasks[_id]()
if task is not None:
self.threadPool.cancel(task)
print(f"Task {_id} canceled.")
try:
self.threadPool.cancel(task)
print(f"Task {_id} canceled.")
except RuntimeError:
print(f"Task {_id} already done.")


def cancelTask(self, fut: Future):
self._taskCancel(fut)
2 changes: 1 addition & 1 deletion demo1.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def onFinished(self, mods: List[schemas.Mod]):
failedCallback=lambda _: print(f"单个加载失败,url={_.url}", _.getException())
)
future.setFailedCallback(lambda _: print("加载失败,failedCallback", _.getException()))
future.done.connect(self.onFutureDone)
future.allDone.connect(self.onFutureDone)
self.fut = future

def onFutureDone(self, result):
Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication

from Plugins.Mod_Plaza.Clients import vacuum
from ui.plazaPage import PlazaPage

if __name__ == '__main__':
Expand Down
178 changes: 0 additions & 178 deletions ui/page.py

This file was deleted.

Loading

0 comments on commit 118a9f7

Please sign in to comment.