Skip to content

Commit

Permalink
Increased the timeout for file creation
Browse files Browse the repository at this point in the history
- If KiCad created the file, but didn't close it now we wait more.

Related to #23
  • Loading branch information
set-soft committed Jun 6, 2022
1 parent 8b4649d commit 4c1ad48
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- An option to use the ray trace end detection with regular (OpenGL) renders
(See #23)

### Changed
- Increased some timeouts, specially when waiting for the file creation (See #23)

### Fixed
- Problems when using PCBs in a read-only dir

Expand Down
52 changes: 30 additions & 22 deletions kiauto/file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,38 @@ def wait_for_file_created_by_process(pid, file):
timeout = 15*time_out_scale
process = psutil.Process(pid)
DELAY = 0.2
logger.debug('Waiting for file %s (pid %d) (timeout: %f)', file, pid, timeout)
for i in range(int(timeout/DELAY)):
kicad_died = False
try:
open_files = process.open_files()
except psutil.AccessDenied:
# Is our child, this access denied is because we are listing
# files for other process that took the pid of the old KiCad.
kicad_died = True
if kicad_died:
raise RuntimeError('KiCad unexpectedly died')
logger.debug(open_files)
if os.path.isfile(file):
file_open = False
for open_file in open_files:
if open_file.path == file:
file_open = True
if file_open:
logger.debug('Waiting for process to close file')
for j in range(2):
# 2 passes: 1) for the file to be created 2) extend the timeout if created
logger.debug('Waiting for file %s (pid %d) (timeout: %f)', file, pid, timeout)
for i in range(int(timeout/DELAY)):
kicad_died = False
try:
open_files = process.open_files()
except psutil.AccessDenied:
# Is our child, this access denied is because we are listing
# files for other process that took the pid of the old KiCad.
kicad_died = True
if kicad_died:
raise RuntimeError('KiCad unexpectedly died')
logger.debug(open_files)
if os.path.isfile(file):
file_open = False
for open_file in open_files:
if open_file.path == file:
file_open = True
if file_open:
logger.debug('Waiting for process to close file')
else:
return
else:
return
logger.debug('Waiting for process to create file')
time.sleep(DELAY)
# If the file was created assume KiCad is working
if os.path.isfile(file):
timeout = 45*time_out_scale
else:
logger.debug('Waiting for process to create file')
time.sleep(DELAY)
# The file wasn't even created, don't wait much
timeout = 1*time_out_scale

raise RuntimeError('Timed out waiting for creation of %s' % file)

Expand Down

0 comments on commit 4c1ad48

Please sign in to comment.