-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.diff
More file actions
25 lines (21 loc) · 915 Bytes
/
patch.diff
File metadata and controls
25 lines (21 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<<<<<<< SEARCH
# Use StringIO to build CSV content asynchronously
import io
output = io.StringIO()
writer = csv.DictWriter(output, fieldnames=self.data[0].keys())
writer.writeheader()
for row in self.data:
writer.writerow(row)
# Write the CSV content to file
async with aiofiles.open(expanded_path, "w") as f:
await f.write(output.getvalue())
=======
import asyncio
def _write_csv(path: str, data: list[dict]):
with open(path, "w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=data[0].keys())
writer.writeheader()
writer.writerows(data)
# Offload CPU-intensive task to thread to prevent blocking event loop and avoid large memory allocations
await asyncio.to_thread(_write_csv, expanded_path, self.data)
>>>>>>> REPLACE