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

Timeout in MagneticStructureEnumerator (and EnumlibAdaptor) does not work #4185

Open
fraricci opened this issue Nov 20, 2024 · 0 comments
Open
Labels

Comments

@fraricci
Copy link
Contributor

fraricci commented Nov 20, 2024

Python version

3.11.5

Pymatgen version

2024.11.13

Operating system version

No response

Current behavior

enum = MagneticStructureEnumerator(structure) should stop after 5 minutes by default,
but it does not. Passing a different timeout does not change anything. I'm now making sure that the timeout arg is passed to the EnumlibAdaptor (see bug in #4184).

I did some tests but I could not figure out why the enum.x process does not get killed.
The main logic from

def _run_multienum(self):
is here:

    def _run_multienum(self):
        with subprocess.Popen([enum_cmd], stdout=subprocess.PIPE, stdin=subprocess.PIPE, close_fds=True) as process:
            if self.timeout:
                timed_out = False
                timer = Timer(self.timeout*60, lambda p: p.kill(), [process])

                try:
                    timer.start()
                    output = process.communicate()[0].decode("utf-8")
                finally:
                    if not timer.is_alive():
                        timed_out = True
                    timer.cancel()

                if timed_out:
                    raise TimeoutError("Enumeration took too long")

            else:
                output = process.communicate()[0].decode("utf-8")

It seems the the process stops communicating. I tried to use the timeout argument
of the process.communicate() method but it does not work neither.

One thing that worked correctly is the same code above with
enum_cmd="/usr/bin/sleep 6000". This process gets killed as it should.

I have the same behavior both in my laptop and on perlmutter.

Any thoughts about what's causing this?

Expected Behavior

enum = MagneticStructureEnumerator(structure) should stop after 5 minutes by default.

Minimal example

No response

Relevant files to reproduce this bug

No response

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

No branches or pull requests

1 participant