Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Travis CI fails intermittently due to file not found #210

Open
dohmatob opened this issue May 27, 2016 · 7 comments
Open

Travis CI fails intermittently due to file not found #210

dohmatob opened this issue May 27, 2016 · 7 comments

Comments

@dohmatob
Copy link
Contributor

It says, IOError: [Errno 2] No such file or directory: '/tmp/titi/func/3.hdr'

@KamalakerDadi
Copy link
Contributor

I am not sure I get this issue. Can you a bit more explicit ?

For me file exists, /tmp/titi/func/3.hdr

@arthurmensch
Copy link
Contributor

I think this is because one of the test function is badly written and writes twice the same data, which creeps travis out. I tried to address it in next PR

@mrahim
Copy link
Collaborator

mrahim commented May 27, 2016

PR Merged. Closing.
Thanks !

@mrahim mrahim closed this as completed May 27, 2016
@dohmatob
Copy link
Contributor Author

The issue still persists (moments, a go I've had to rebuild a PR, because is failed thus). Re-opening.

@lesteve
Copy link
Contributor

lesteve commented Jan 18, 2017

I can reproduce locally but you have to clean the files in /tmp/titi (maybe by sending a grosminet):

rm -rf /tmp/titi && nosetests pypreprocess/tests/test_subject_data.py -m test_not_uniq

Doing that in a loop I get 10-20 failures for 100 attempts:

(for i in $(seq 1 100); do
    rm -rf /tmp/titi && nosetests pypreprocess/tests/test_subject_data.py -m test_not_uniq
done) 2>&1 | tee test.log

In general it is not great that the tests leave files around after finishing, also you should probably use tempfile.NamedTemporaryFile rather than hard-coded files in /tmp. I have no clue about the root cause of the failure, but maybe using different filenames with tempfile.NamedTemporaryFile would fix this issue ...

@lesteve
Copy link
Contributor

lesteve commented Jan 19, 2017

I debugged this further, and there is a problem in _make_sd when func_filenames has nested lists. I lack domain knowledge to understand what this function does, but here is the code and look at the comment inside for the explanation of where it goes wrong:

def _make_sd(func_filenames=None, anat_filename=None, ext=".nii.gz",
             n_sessions=1, make_sess_dirs=False, func_ndim=4,
             unique_func_names=False, output_dir="/tmp/titi"):
    if not func_filenames is None:
        n_sessions = len(func_filenames)
    func = [create_random_image(ndim=func_ndim) for _ in range(n_sessions)]
    anat = create_random_image(ndim=3)
    if anat_filename is None:
        anat_filename = '%s/anat%s' % (DATA_DIR, ext)
    _save_img(anat, anat_filename)
    if not func_filenames is None:
        for sess_func, filename in zip(func, func_filenames):
            if isinstance(filename, _basestring):
                _save_img(sess_func, filename)
            else:
                vols = nibabel.four_to_three(sess_func)
                # The problem is that sess_func (a random 4d image)
                # can have 1 as the last dimension. If that happens
                # vols has one element only.  In the test
                # func_filename is a list of list of 2 elements
                # [['img1', 'img2'], ['img3', 'img4']] so filename has
                # 2 elements. That means that the zip on the next line
                # is only over 1 element and you only write one file
                # out of the two you are supposed to write, hence the
                # FileNotFoundError
                for x, y in zip(vols, filename):
                    assert isinstance(y, _basestring), type(y)
                    _save_img(x, y)
    else:
        func_filenames = []
        for sess in range(n_sessions):
            sess_dir = DATA_DIR if not make_sess_dirs else os.path.join(
                DATA_DIR, "session%i" % sess)
            if not os.path.exists(sess_dir):
                os.makedirs(sess_dir)
            func_filename = '%s/func%s%s' % (
                sess_dir, "_sess_%i_" % sess if (
                    n_sessions > 1 and unique_func_names) else "", ext)
            _save_img(func[sess], func_filename)
            func_filenames.append(func_filename)

    sd = SubjectData(anat=anat_filename,
                     func=func_filenames,
                     output_dir=output_dir)
    return sd

@thomasbazeille
Copy link

Update on this : @lesteve did the hardwork here and his last comment is right on point. But this bug is still happening randomly sometimes, I will redesign the concerned test to make it deterministic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants