diff --git a/CHANGELOG.md b/CHANGELOG.md index e56a917..3a068e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/kiauto/file_util.py b/kiauto/file_util.py index b1bd672..576a4d4 100644 --- a/kiauto/file_util.py +++ b/kiauto/file_util.py @@ -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)