apache / apache/arrow

Exception on csv.read_csv() leaves opened handle on Windows

Open
#38,812 0 comments 0 reactions 0 assignees View on GitHub
Component: C++ Component: Python Type: bug
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 13h
Merged PRs (30d)
88

Description

### Describe the bug, including details regarding any error messages, version, and platform.

On Windows via pyarrow reading CSV file with a very, very, very long field (several million characters).
Since we don't know ahead of time length of the column - keep trying to read doubling buffer size.
Issue is that upon exception file seems to be not properly closed leaving an open handle and preventing temporary file(s) from being removed.
Python code:
```
while True:
try:
table = csv.read_csv(csv_file_path, read_options=read_options, parse_options=parse_options,
convert_options=convert_options)
break
except pa.lib.ArrowInvalid:
print(f'Doubling CSV block_size from {read_options.block_size}')
read_options.block_size *= 2
```

This issue is possibly related to https://github.com/apache/arrow/issues/31796 since it seems to be about properly closing file handles on Windows.

### Component(s)

C++, Python

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.