Skip to content

tqdm>= 4.70 changes how iterators are handled #5540

Open
Srikar025/mdanalysis
#1

Description

@hejamu

Expected behavior

An iteration through the trajectory that ran into an exception (also includes stopping execution in a notebook) keeps the Universe unchanged.

Actual behavior

tdqm closes the TrajectoryReader.

We ran into this because our test suite runs the MDAnalysis API tests against our AnalysisBase and ran test_incomplete_defined_analysis before test_old_api, and that one kept failing.

I traced the problem back to this small change in tqdm (tqdm/tqdm@5dcb022). This removed the protection around the iterator.

In principle this is expected behaviour, tqdm does that self.close() statements to clean up iterators on errors.

The normal AnalysisBase seems to be safe because it always runs the trajectory through the sliced iterator.

Our fix is now this atomistic-lab/maicos#614

Code to reproduce the behavior

Somehow stop execution during iteration. I did it in a notebook by stopping execution of the cell

import MDAnalysis as mda
from time import sleep

#import test files
from MDAnalysis.tests.datafiles import PSF, DCD,  GRO, PDB, TPR, XTC, TRR,  PRMncdf, NCDF

from MDAnalysis.lib.log import ProgressBar

print(mda.__version__)

u = mda.Universe(TPR, XTC)

for ts in ProgressBar(u.trajectory, verbose=False):
    print(ts.frame)
    sleep(10)

u.trajectory[0].frame

results in OSError: No file currently opened

Current version of MDAnalysis

  • Which version are you using? (run python -c "import MDAnalysis as mda; print(mda.__version__)")
    2.11.0
  • Which version of Python (python -V)?
    3.15.0
  • Which operating system?
    macOS 27.2

Activity

  1. Smruti0603 commented on Nov 6, 2026

    @Smruti0603

    Hey @hejamu, I am new here, Would like to pick this issue.. Can you assign it to me ?

  2. RMeli commented on Nov 6, 2026

    @RMeli
    Member

    Hi @Smruti0603, welcome to MDAnalysis! In general, we do not assign issues. If an issue has no open PR, then feel free to work on it and open a PR when ready.

  3. orbeckst commented on Nov 13, 2026

    @orbeckst
    Member

    @hejamu thanks for the detailed report. Would you be interested in reviewing the PR #5546 and check if it fixes the issues?

  4. Srikar025 commented on Nov 15, 2026

    @Srikar025

    Hi! This PR fixes #5540 . I've merged the latest develop, all 25 checks are passing, and patch coverage is 100%. Could someone with write access take a look when you have time? Happy to make any changes you'd like. Thanks

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions