Giter Site home page Giter Site logo

Comments (7)

lukelbd avatar lukelbd commented on August 21, 2024 1

Think this issue can be closed (see #44 merge)

from cdo-bindings.

Try2Code avatar Try2Code commented on August 21, 2024

hi!
I didn't get a notification, sorry. Could you use ctrl-D? it works for me.

from cdo-bindings.

nikola-rados avatar nikola-rados commented on August 21, 2024

Hello! Sorry I must have missed your notification as well. No, crtl-D doesn't work. Here is what the terminal output looks like when I try to crtl-C:

^Ccaught signal <cdo.Cdo object at 0x7f9c262dde10> 2 <frame object at 0x2307e88

from cdo-bindings.

Try2Code avatar Try2Code commented on August 21, 2024

I work on a new cdo.py release 2.0 with a new interface. Will take of this for 2.0 then.

thx for your patience

from cdo-bindings.

nikola-rados avatar nikola-rados commented on August 21, 2024

No problem! Thank you for addressing the issue.

from cdo-bindings.

lukelbd avatar lukelbd commented on August 21, 2024

Think I duplicated this issue in #43. Also here's a possible workaround (although I can't test it -- seems the current master branch does not work right now). Inside Cdo.__init__ I replace the signal definitions with this:

        # handling different exits from interactive sessions {{{
        # python3 has threading.main_thread(), but python2 doesn't
        import functools
        if sys.version_info[0] == 2 \
                or threading.current_thread() is threading.main_thread():
            sigint_default = signal.getsignal(signal.SIGINT)
            sigterm_default = signal.getsignal(signal.SIGTERM)
            sigsegv_default = signal.getsignal(signal.SIGSEGV)
            sigint = functools.partial(self.__catch__, default=sigint_default)
            sigterm = functools.partial(self.__catch__, default=sigterm_default)
            sigsegv = functools.partial(self.__catch__, default=sigsegv_default)
            signal.signal(signal.SIGINT,  sigint)
            signal.signal(signal.SIGTERM, sigterm)
            signal.signal(signal.SIGSEGV, sigsegv)

and then replace Cdo.__catch__ with the following lines that throw the default handler after removing tempfiles:

    def __catch__(self, signum, frame, default=None):
        self.tempStore.__del__()
        if callable(default):
            default()
        else:
            print("caught signal", self, signum, frame)

from cdo-bindings.

lukelbd avatar lukelbd commented on August 21, 2024

Ok while I couldn't test the above solution on the master branch, here's a simple workaround that succeeds with the latest stable version. I just call cdo = _init_cdo() instead of cdo = Cdo() in the python script or interactive session:

import signal
import threading
from cdo import Cdo
def _cdo_handler(cdo, handler):
    def _handle_signal(*args, **kwargs):
        cdo.tempStore.__del__()
        handler(*args, **kwargs)
    return _handle_signal
def _init_cdo():
    sigint = signal.getsignal(signal.SIGINT)
    sigterm = signal.getsignal(signal.SIGTERM)
    sigsegv = signal.getsignal(signal.SIGSEGV)
    cdo = Cdo()
    signal.signal(signal.SIGINT, _cdo_handler(cdo, sigint))
    signal.signal(signal.SIGTERM, _cdo_handler(cdo, sigterm))
    signal.signal(signal.SIGSEGV, _cdo_handler(cdo, sigsegv))
    return cdo

from cdo-bindings.

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.