Coder Social home page Coder Social logo

code is never stopped about async-timeout HOT 3 CLOSED

aio-libs avatar aio-libs commented on May 14, 2024
code is never stopped

from async-timeout.

Comments (3)

Dreamsorcerer avatar Dreamsorcerer commented on May 14, 2024 1

That's not how asyncio works, we can't cancel if you don't yield back to the event loop anywhere (e.g. with an await).

Use await asyncio.sleep(1), not time.sleep(), which is a blocking function resulting in your application not being able to handle any other async tasks.

from async-timeout.

viniavila avatar viniavila commented on May 14, 2024

Ah how do I abort an execution from an external library without support to async calls? I'm using the package
rdkit and the function rdkit.Chem.rdDetermineBonds.DetermineBondOrders sometimes takes forever to execute, and I want to add a timeout funcionality. I was hoping async-timeout would save me, but when I write this code:

async with timeout(1):
    await rdDetermineBonds.DetermineBondOrders(conn_mol, charge=mol_charge)

To force rdDetermineBonds.DetermineBondOrders abort after 1 second, raising an error (that I will catch as Exception in my code). But it didn't work! Am I having a wrong understanding about how async works? My problem can be solved using this library?

EDIT: I'm not willing to deal with rdkit source code, so I wish an external solution.

from async-timeout.

Dreamsorcerer avatar Dreamsorcerer commented on May 14, 2024

It should work, so I'd file a bug against rdkit if it doesn't. The reasons that the timeout doesn't work are likely that rdkit isn't yielding to the event loop (which they should be if it's meant to be an async interface), or they are catching and suppressing the CancelledError.

from async-timeout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.