{ "info": { "author": "KuraLabs S.R.L", "author_email": "info@kuralabs.io", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3" ], "description": "=========\nmultiexit\n=========\n\nA better, saner and more useful atexit_ replacement for Python 3 that supports\nmultiprocessing_.\n\nInspired by the following StackOverflow question and experience on building\nmultiprocessing daemons:\n\nhttps://stackoverflow.com/q/2546276\n\n.. _atexit: https://docs.python.org/3/library/atexit.html\n.. _multiprocessing: https://docs.python.org/3/library/multiprocessing.html\n\n``multiexit`` will install a handler for the SIGTERM and SIGINT signals and\nexecute the registered exit functions in *LIFO* order (Last In First Out).\n\nExit functions can be registered so that only the calling process will call\nthem (the default), or as *shared* exit functions that will be called by the\ncalling process and all the children subprocesses that inherit it.\n\n\nInstall\n=======\n\n``multiexit`` is available for Python 3 from PyPI_.\n\n.. _PyPI: https://pypi.python.org/pypi/multiexit/\n\n.. code-block:: sh\n\n pip3 install multiexit\n\n\nAPI\n===\n\nOn the main process, before forking or creating any subprocess, call\n``multiexit.install``:\n\n.. code-block:: python\n\n def install(\n signals=(signal.SIGTERM, signal.SIGINT),\n except_hook=True,\n )\n\n:signals:\n Signals to install handler. Usually only ``SIGTERM`` and ``SIGINT`` are\n required.\n\n:except_hook:\n Also install a `sys.excepthook`_ that will call the exit functions in case of\n an unexpected exception.\n\n.. _`sys.excepthook`: https://docs.python.org/3/library/sys.html#sys.excepthook\n\nThen, for each exit function, on any subprocess, call ``multiexit.register``:\n\n.. code-block:: python\n\n register(func, shared=False)\n\n:func:\n Exit function to register. Any callable without arguments.\n\n:shared:\n If ``shared``, the exit function will be called by the calling process but\n also by all the children subprocesses that inherit it (thus the ones\n created after registering it).\n If ``shared`` is ``False``, the default, only the calling process will execute\n the exit function.\n\n\nExample\n=======\n\n.. code-block:: python\n\n from time import sleep\n from signal import SIGTERM\n from os import kill, getpid\n from multiprocessing import Process\n\n from multiexit import install, register, unregister\n\n\n if __name__ == '__main__':\n\n # Always call install() on the main process before creating any\n # subprocess\n #\n # This installs a handler for SIGTERM and SIGINT. Subprocesses will\n # inherit this handler. It also assigns the current PID as the master\n # process, which will allow to choose between exit or os._exit calls\n # when quitting.\n install()\n\n def _subproc1():\n\n @register\n def subproc1_clean():\n print('Subprocess clean!')\n\n sleep(1000)\n\n # Register shared exit function so all subprocess call this\n def shared_exit():\n print('Shared exit being called by {} ...'.format(getpid()))\n\n register(shared_exit, shared=True)\n\n subproc1 = Process(\n name='SubProcess1',\n target=_subproc1,\n )\n # proc.daemon = True\n # daemon means that signals (like SIGTERM) will be propagated automatically\n # to children. Set to false (the default), to handle the SIGTERM\n # (process.terminate()) to the children yourself.\n subproc1.start()\n\n # Register a cleaner using a decorator\n @register\n def clean_main():\n print('Terminating child {}'.format(\n subproc1.pid,\n ))\n subproc1.terminate()\n subproc1.join()\n print('Child {} ended with {}'.format(\n subproc1.pid,\n subproc1.exitcode,\n ))\n\n # Wait, and then kill main process\n sleep(3)\n\n # Suicide\n kill(getpid(), SIGTERM)\n\nFor a more extensive example check out ``example.py``.\n\n\nChanges\n=======\n\n1.5.0\n-----\n\nA ``SIGINT`` handler is now installed by default to handle Ctrl+C. This\nmeans that Python's ``signal.default_int_handler`` is overridden, thus\nCtrl+C no longer raises ``KeyboardInterrupt``. If this behavior is\nundesired, pass ``signals=(signal.SIGTERM)`` when calling ``install()``.\n\nCtrl+C sends ``SIGINT`` to all processes in the terminal's foreground\nprocess group, so in order to behave like a ``SIGTERM`` shutdown flow, which\nis sent only on the parent process, the handler will ignore ``SIGINT`` on\nthe children to allow the parent to decide what to do with the subprocesses\nand their corresponding shutdown sequence.\n\nThis fixes issue #3\n\n\nLicense\n=======\n\n::\n\n Copyright (C) 2018-2019 KuraLabs S.R.L\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing,\n software distributed under the License is distributed on an\n \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n KIND, either express or implied. See the License for the\n specific language governing permissions and limitations\n under the License.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/kuralabs/multiexit", "keywords": "multiexit multiprocessing atexit", "license": "", "maintainer": "", "maintainer_email": "", "name": "multiexit", "package_url": "https://pypi.org/project/multiexit/", "platform": "", "project_url": "https://pypi.org/project/multiexit/", "project_urls": { "Homepage": "https://github.com/kuralabs/multiexit" }, "release_url": "https://pypi.org/project/multiexit/1.5.0/", "requires_dist": null, "requires_python": "", "summary": "atexit replacement that supports multiprocessing", "version": "1.5.0", "yanked": false, "yanked_reason": null }, "last_serial": 6015812, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "762045440613991c13463f61e7a99b17", "sha256": "11d98fc932a1499ea0e2c9f0b6b397d0e9039c57a8b4317e58e60b77c642d503" }, "downloads": -1, "filename": "multiexit-1.0.0-py3-none-any.whl", "has_sig": true, "md5_digest": "762045440613991c13463f61e7a99b17", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3462, "upload_time": "2018-04-07T05:00:06", "upload_time_iso_8601": "2018-04-07T05:00:06.955672Z", "url": "https://files.pythonhosted.org/packages/9a/c2/baa841e0833fc85623fa586697292aa326e0b1bd226c8f025bf3302e7341/multiexit-1.0.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "30896ef46f00dfce68e516e6eaa3b5e2", "sha256": "e87a4917c7ed52ad1282e5ea718754c204fd00b2322cad106736a51cc6caa189" }, "downloads": -1, "filename": "multiexit-1.1.0-py3-none-any.whl", "has_sig": true, "md5_digest": "30896ef46f00dfce68e516e6eaa3b5e2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4117, "upload_time": "2018-04-07T09:56:04", "upload_time_iso_8601": "2018-04-07T09:56:04.656582Z", "url": "https://files.pythonhosted.org/packages/6a/c9/24e516b618b530abe5c1cf97b61b14c93782add503520d9969a5c455e2b1/multiexit-1.1.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "83448ac3af9ca3c12136b486688e2900", "sha256": "7d1998e5fe3b3818b4de1c9969c1b761c5f66165b52e24596dc6121ae535f900" }, "downloads": -1, "filename": "multiexit-1.2.0-py3-none-any.whl", "has_sig": true, "md5_digest": "83448ac3af9ca3c12136b486688e2900", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4256, "upload_time": "2018-04-07T11:27:28", "upload_time_iso_8601": "2018-04-07T11:27:28.942533Z", "url": "https://files.pythonhosted.org/packages/0a/cb/b25d3510ac6eb6e133647d2780bd7c3dbcb3062e75db3015616fb3afa9b8/multiexit-1.2.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "1.3.0": [ { "comment_text": "", "digests": { "md5": "7b15554d37710613a19d893e4a3086f0", "sha256": "79acd82c346dac5b5f202437de7e193de20890a62765a38efacd2ad75251f7c7" }, "downloads": -1, "filename": "multiexit-1.3.0-py3-none-any.whl", "has_sig": true, "md5_digest": "7b15554d37710613a19d893e4a3086f0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4408, "upload_time": "2018-04-07T11:40:34", "upload_time_iso_8601": "2018-04-07T11:40:34.546167Z", "url": "https://files.pythonhosted.org/packages/93/41/5651e780b79a2a0b311733259c929574ef9a0493774c32597b7aff62cc91/multiexit-1.3.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "1.4.0": [ { "comment_text": "", "digests": { "md5": "c0cabb98d5628a905d7673c5bdd3af9c", "sha256": "f3b6f9ed2d9b5eb09d0653726509a7df05a7cdab9e57e9481c22ac02d6a09c92" }, "downloads": -1, "filename": "multiexit-1.4.0-py3-none-any.whl", "has_sig": true, "md5_digest": "c0cabb98d5628a905d7673c5bdd3af9c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4985, "upload_time": "2018-04-10T22:49:10", "upload_time_iso_8601": "2018-04-10T22:49:10.447234Z", "url": "https://files.pythonhosted.org/packages/18/5f/d4bbf79ff2c37aba5f1ba443d7d3d1626d2c11589aa58d0cfb7913ea8759/multiexit-1.4.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "1.4.1": [ { "comment_text": "", "digests": { "md5": "e1918b8112c7714c8b9e55a425ede39b", "sha256": "1af7b96b81e1546aa7294db10fa0d2a45c362ac9b1a0a5e8a9adacb085d6c35e" }, "downloads": -1, "filename": "multiexit-1.4.1-py3-none-any.whl", "has_sig": true, "md5_digest": "e1918b8112c7714c8b9e55a425ede39b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4988, "upload_time": "2018-04-10T22:55:49", "upload_time_iso_8601": "2018-04-10T22:55:49.462635Z", "url": "https://files.pythonhosted.org/packages/c4/18/f7395530393ca08b384cb1d0f3ebcc827e5c580b29661076173382878536/multiexit-1.4.1-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "1.5.0": [ { "comment_text": "", "digests": { "md5": "1fd63a5fe24dacf9a2977b1731fc3427", "sha256": "aa773f041e917a536ad58834bef7e08e6bcd1af2d09d9cd1ea8e5ac3719fcfed" }, "downloads": -1, "filename": "multiexit-1.5.0-py3-none-any.whl", "has_sig": false, "md5_digest": "1fd63a5fe24dacf9a2977b1731fc3427", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9682, "upload_time": "2019-10-22T23:59:54", "upload_time_iso_8601": "2019-10-22T23:59:54.107100Z", "url": "https://files.pythonhosted.org/packages/9c/8b/5e74b740675eee47792c4e2cae0815427820395e54992548d8fc99c90656/multiexit-1.5.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1fd63a5fe24dacf9a2977b1731fc3427", "sha256": "aa773f041e917a536ad58834bef7e08e6bcd1af2d09d9cd1ea8e5ac3719fcfed" }, "downloads": -1, "filename": "multiexit-1.5.0-py3-none-any.whl", "has_sig": false, "md5_digest": "1fd63a5fe24dacf9a2977b1731fc3427", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9682, "upload_time": "2019-10-22T23:59:54", "upload_time_iso_8601": "2019-10-22T23:59:54.107100Z", "url": "https://files.pythonhosted.org/packages/9c/8b/5e74b740675eee47792c4e2cae0815427820395e54992548d8fc99c90656/multiexit-1.5.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }