Code Monkey home page Code Monkey logo

multiexit's People

Contributors

carlos-jenkins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

wood-j taksunghun

multiexit's Issues

Doesn't work when execution completes.

Python's atexit is designed, so that func gets called when

At normal program termination (for instance, if sys.exit() is called or the main module’s execution completes

But with multiexit, func only gets called on termination by a signal, not on simple module completion!

Register on a function with argument

Hi,

First of all, thank you for making multiexit :)

I was wondering if it was possible to register ()
a function with one argument?

Here is an example :

#!/usr/bin/env python
# coding: utf-8

import requests
from multiexit import install, register, unregister, run_exitfuncs
#import multiexit
from os import getpid
import signal



install(signals=(signal.SIGTERM, signal.SIGINT),except_hook=True)
def shared_exit():
    print('Shared exit being called by {} ...'.format(getpid()))

register(shared_exit, shared=True)

@register
def test_get(url):
    response = requests.request("GET", url)
    print(response.status_code)


#global url 
url = 'https://duckduckgo.com/?q=plop&t=h_&ia=definition'

raise Exception('My error!')

Currently, this does not seem to work, the agurment
is not passing to the function and we have this error:

Uncaught exception
Traceback (most recent call last):
  File "plop.py", line 27, in <module>
    raise Exception('My error!')
Exception: My error!
Exit function <function test_get at 0x7f64ad61cd08> failed:
Traceback (most recent call last):
  File "/data/[user]/home/.local/share/virtualenvs/venv_test_3.6.9/lib/python3.6/site-packages/multiexit.py", line 75, in run_exitfuncs
    func()
TypeError: test_get() missing 1 required positional argument: 'url'
Shared exit being called by 24182 ...

Maybe it's not possible or it's against the ideology of this module ?

I'm happy to contribute a PR if we agree on a solution and you guys think
it's worth doing.

[Advice] Should I use this for my project?

Hello, I am trying to build this library for multiprocessing

https://github.com/devxpy/zproc

It currently claims that

Remembers to kill processes when exiting, for general peace.

But I noticed that processes that are spawned from inside another process dont get cleaned up properly.

Only those processes that were spawned from the parent are cleaned up.

I am currently using atexit to register cleanup using os.kill() (registered as soon as you spawn a new Process.). You may see the corresponding code here and here.

This is my cleanup function.

Do you think this lib will be able to help me with this?

It doesn't seem to work from inside a class.

Doesn't seem to work from inside classes.

    @multiexit.register
  File "/redacted/redacted/redacted/venv/lib/python3.6/site-packages/multiexit.py", line 168, in register
    current_handler,
RuntimeError: multiexit signal handler isn't installed. Unknown signal handler 0. Please call install() once on the maim process before starting any subprocess.

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.