import tarfile from concurrent.futures.thread import ThreadPoolExecutor from io import BytesIO def test_lzma(x): buf = BytesIO() with tarfile.open(fileobj=buf, mode="w") as archive: tarinfo = tarfile.TarInfo(name="x") tarinfo.size = 1 archive.addfile(tarinfo=tarinfo, fileobj=BytesIO(b"x")) buf.seek(0) tarfile.open(fileobj=buf, mode="r") print("SUCCESS", x) with ThreadPoolExecutor(max_workers=5) as pool: list(pool.map(test_lzma, range(100)))