Sen2cor fails on first attempt but works on second attempt


I have the stand alone version of sen2cor 2.5.5 installed on a Linux system. If I try to run L2A_Process ‘file’ from the command line, it always fails with the response “nonetype has no attribute get” on the first attempt, but it runs correctly on the second attempt. Has anyone run into a similar issue before?

Thank you,


Yes. Sen2Cor is very unstable. I’ve had it happen that the L2A_Process program had a segmentation fault the first two times I ran it and then it worked the third time. I’m now always retrying L2A_Process at least 4 times in my processing chain before I consider it failed.

Thanks for the advice. Would you mind sharing how you implemented the retrying functionality into your processing chain?

I’ve implemented it in Python but similar things should work in any language.

Something like the following should do it. This also includes a timeout because I’ve had Sen2Cor just hang on some scenes. Sen2Cor really is a horrible program :slight_smile:

import subprocess32 as subprocess
import os

logfile_path = os.path.join('some', 'path')
l2a_ident = 'l2a_scene_id'

cmd_list = ['path/to/sen2cor/bin/L2A_Process', 'scene_dir',
            '--resolution', '20', '--GIP_L2A', 'your_config.xml']

tries = 1

retries = 4

while tries < retries:
        error_out = os.path.join(
            logfile_path, '{}.error'.format(l2a_ident))
        stdout_out = os.path.join(
            logfile_path, '{}.log'.format(l2a_ident))
        with open(error_out, 'w') as err_file:
            with open(stdout_out, 'w') as log_file:
                # we only allow a maximum of 40 minutes for a sen2cor call
                # if it takes longer it most likely hangs and
                # we want to kill it and try again
    except subprocess.CalledProcessError:
        tries = tries + 1

This is very useful. Thank you for all the help.