Skip to content

Commit

Permalink
Fix error with temp file read access on Windows
Browse files Browse the repository at this point in the history
Attempting to access the temp file after creation on Windows will trigger Permission Error.
The fix is to set the the delete flag to False (which is a quick and dirty hack),
which allows Python to 'release' the file handle, resulting in successful subsequent read access under Windows.

Docs reference: https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
`Whether the name can be used to open the file a second time, while the named temporary file is still open,
varies across platforms (it can be so used on Unix; it cannot on Windows NT or later)`

Fixes #255
  • Loading branch information
int3l authored Mar 1, 2020
1 parent 7fef19f commit 500299f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/pytesseract.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def prepare(image):
@contextmanager
def save(image):
try:
with NamedTemporaryFile(prefix='tess_') as f:
with NamedTemporaryFile(prefix='tess_', delete=False) as f:
if isinstance(image, str):
yield f.name, realpath(normpath(normcase(image)))
return
Expand Down

0 comments on commit 500299f

Please sign in to comment.