remove pool manager and threads
This commit is contained in:
parent
26ff59eb8d
commit
1dc9fccdc4
@ -5,9 +5,6 @@ import shutil
|
|||||||
import time
|
import time
|
||||||
import urllib3
|
import urllib3
|
||||||
|
|
||||||
from threading import Thread
|
|
||||||
from urllib3 import PoolManager
|
|
||||||
|
|
||||||
FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
|
FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
|
||||||
logging.basicConfig(format=FORMAT, level=logging.INFO)
|
logging.basicConfig(format=FORMAT, level=logging.INFO)
|
||||||
|
|
||||||
@ -29,9 +26,9 @@ FILES = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_files(http: PoolManager, filename: str, outdir: str):
|
def get_file(filename: str, outdir: str):
|
||||||
with open(os.path.join(outdir, filename), "wb") as out:
|
with open(os.path.join(outdir, filename), "wb") as out:
|
||||||
r = http.request("GET", f"{URL}/{filename}", preload_content=False)
|
r = urllib3.request("GET", f"{URL}/{filename}", preload_content=False)
|
||||||
shutil.copyfileobj(r, out)
|
shutil.copyfileobj(r, out)
|
||||||
|
|
||||||
|
|
||||||
@ -56,15 +53,7 @@ if __name__ == "__main__":
|
|||||||
logging.fatal(e)
|
logging.fatal(e)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
threads = []
|
|
||||||
http = urllib3.PoolManager()
|
|
||||||
|
|
||||||
for f in FILES:
|
for f in FILES:
|
||||||
t = Thread(target=get_files, args=[http, f, jaymod_dir])
|
get_file(f, jaymod_dir)
|
||||||
threads.append(t)
|
|
||||||
t.start()
|
|
||||||
|
|
||||||
for t in threads:
|
|
||||||
t.join()
|
|
||||||
|
|
||||||
logging.info(f"elapsed time: {time.perf_counter() - start:.2f}s")
|
logging.info(f"elapsed time: {time.perf_counter() - start:.2f}s")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user