{ "info": { "author": "Vincent Driessen", "author_email": "vincent@datafox.nl", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Operating System :: POSIX", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "===================================================\n drainers - Event-based draining of process output\n===================================================\n\ndrainers is an abstraction around `subprocess.Popen` to read and control\nprocess output event-wise. It also allows you to abort running processes\neither gracefully or forcefully without having to directly interact with the\nprocesses or threads themself.\n\nOverview\n========\n\nDefining a process\n------------------\nA `Drainer` is a factory and controller wrapper around\n`subprocess.Popen` and therefore takes all of the (optional) parameters\nthat `subprocess.Popen`'s initializer takes. For example, the minimal\n`Drainer` takes a command array::\n\n\tfrom drainers import Drainer\n\n\tdef ignore_event(line, is_err):\n\t\tpass\n\n\tmy_drainer = Drainer(['ls', '-la'], read_event_cb=ignore_event)\n\tmy_drainer.start()\n\nBut, extra arguments are allowed, too::\n\n\tmy_drainer = Drainer(['echo', '$JAVA_HOME'], shell=True, bufsize=64,\n\t\t\t\t\t\t read_event_cb=ignore_event)\n\tmy_drainer.start()\n\nThe only two arguments to `Drainer` that are reserved are\n`stdout` and `stderr`. `Drainer` requires them to be\n`subprocess.PIPE` explicitly, and sets them for you accordingly.\n\nDefining a callback\n-------------------\n`Drainer`'s strength lies in the fact that each line that is read from the\nprocess' standard output or standard error streams leads to a callback\nfunction being invoked. This allows you to process virtually any process'\noutput, as long as it's line-based.\n\nThe callback function can be specified using the `read_event_cb` parameter to\nthe constructor, as seen in the example above. It is mandatory. The callback\nfunction specified needs to have a specific signature::\n\n\tdef my_callback(line, is_err):\n\t\t...\n\nIt should take two parameters: `line` (a string) and `is_err` (a boolean).\nThe latter indicates that the line is read from the standard error stream.\nThere is nothing more to it. It does not need to return anything: it's return\nvalue will be ignored. Your callback may be a class method, too, like in the\nfollowing example. Notice that in those cases, you pass `foo.my_method` as\nthe value for the `read_event_cb` parameter::\n\n\tclass MyClass(object):\n\n\t\tdef my_method(self, line, is_err):\n\t\t\t...\n\t\n\tfoo = MyClass()\n\tmy_drainer = Drainer(['ls'], read_event_cb=foo.my_method)\n\tmy_drainer.start()\n\nThe granularity currently is a single line. If you want to read predefined\nchunks (lines) of data, use `BufferedDrainer` instead. See\nexamples/buffer_results.py for an example.\n\nAborting processes\n------------------\n`Drainer` allows you to abort a running process in the middle of execution,\nforcefully sending the process a `terminate()` message (Python equivalent of a\nUnix `SIGTERM` message) when a certain condition arises. By default, the\nprocess will never be terminated abnormally. To specify termination criteria,\nimplement a callback function that takes no parameters and returns `True` if\nabortion is desired and `False` otherwise. For example, for a long running\nprocess you might want to terminate it if the disk is getting (almost) full.\nBut checking how much space is free can be a lengthy operation, so you might\nwant to do it only sparingly::\n\n\tdef out_of_diskspace():\n\t\tleft = handytools.check_disk_free()\n\t\ttotal = handytools.check_disk_total()\n\t\treturn (left / total) < 0.03\n\n\t# The following drainer executes the cruncher and checks whether the disk\n\t# is (almost) full every 5 seconds. It aborts if free disk space runs\n\t# under 3%.\n\tmy_drainer = Drainer(['/bin/crunch', 'inputfile', 'outputfile'],\n\t read_event_cb=ignore_event,\n\t\t\t\t\t\t should_abort=out_of_diskspace,\n\t\t\t\t\t\t check_interval=5.0)\n\texitcode = my_drainer.start()\n\nThe example is pretty self-explaining. You can check the exitcode to see the\nresult of the process.\n\n\nMore examples\n=============\nSee the `examples` directory for more detailed examples.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/nvie/python-drainers/", "keywords": null, "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "drainers", "package_url": "https://pypi.org/project/drainers/", "platform": "any", "project_url": "https://pypi.org/project/drainers/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/nvie/python-drainers/" }, "release_url": "https://pypi.org/project/drainers/0.0.3/", "requires_dist": null, "requires_python": null, "summary": "Event-based draining of process output", "version": "0.0.3" }, "last_serial": 663295, "releases": { "0.0.1": [], "0.0.2": [], "0.0.3": [ { "comment_text": "", "digests": { "md5": "bf61d5c553d16c9b87ef9d2b035a3015", "sha256": "813fc8725567e0e7fffe1554b33d856bd75f7c86995f1253e1a10688a6a40d5c" }, "downloads": -1, "filename": "drainers-0.0.3.tar.gz", "has_sig": false, "md5_digest": "bf61d5c553d16c9b87ef9d2b035a3015", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8987, "upload_time": "2010-06-04T16:27:28", "url": "https://files.pythonhosted.org/packages/22/da/c6d10618a9b5baf6c466b0def4b3b3d79203c6075ad38fef4d33087ccb53/drainers-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bf61d5c553d16c9b87ef9d2b035a3015", "sha256": "813fc8725567e0e7fffe1554b33d856bd75f7c86995f1253e1a10688a6a40d5c" }, "downloads": -1, "filename": "drainers-0.0.3.tar.gz", "has_sig": false, "md5_digest": "bf61d5c553d16c9b87ef9d2b035a3015", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8987, "upload_time": "2010-06-04T16:27:28", "url": "https://files.pythonhosted.org/packages/22/da/c6d10618a9b5baf6c466b0def4b3b3d79203c6075ad38fef4d33087ccb53/drainers-0.0.3.tar.gz" } ] }