Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cooper@home1:/data/psx$ cat extract.py
- #!/usr/bin/env python3
- import asyncio
- import multiprocessing
- from pathlib import Path
- async def extract_file(q):
- f = await q.get()
- print(f"-> Extracting {f}")
- proc = await asyncio.create_subprocess_shell(
- f"7z e '{f}' && rm -f '{f}'",
- stdout=asyncio.subprocess.PIPE,
- stderr=asyncio.subprocess.PIPE)
- _stdout, _stderr = await proc.communicate()
- if proc.returncode == 0:
- print(f"--> Finished {f}")
- else:
- print(f"!!> FAILED {f}")
- async def main():
- PSX_PATH = Path(__file__).parent
- all_files = PSX_PATH.glob("*.7z")
- q = asyncio.Queue()
- for f in PSX_PATH.glob("*.7z"):
- await q.put(f)
- coros = []
- for i in range(int(multiprocessing.cpu_count()/2)):
- coros.append(extract_file(q))
- await asyncio.gather(*coros)
- asyncio.run(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement