prefetch-generator


Nameprefetch-generator JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://github.com/justheuristic/prefetch_generator
Summarya simple tool to compute arbitrary generator in a background thread
upload_time2022-11-19 14:38:34
maintainer
docs_urlNone
author
requires_python
licenseThe Unlicense
keywords background generator prefetch generator parallel generator prefetch background deep learning theano tensorflow lasagne blocks
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Based on http://stackoverflow.com/questions/7323664/python-generator-pre-fetch

This is a single-function package that makes it possible to transform any generator into a `BackgroundGenerator` which computes any number of elements from the generator ahead, in a background thread.

It is quite lightweight, but not entirely weightless.

The `BackgroundGenerator` is most useful when you have a GIL releasing task which might take a long time to complete (e.g. Disk I/O, Web Requests, pure C functions, GPU processing, ...), and another task which takes a similar amount of time, but is dependent on the results of the first task (e.g. Computationally intensive processing of data loaded from disk).

Normally these two tasks will constantly wait for one another to finish. If you make one of these tasks a `BackgroundGenerator` (see examples below), they will work in parallel, potentially saving up to 50% of execution time (definitely less in practice).

We personally use the `BackgroundGenerator` when iterating over minibatches of data for deep learning with tensorflow and theano ( lasagne, blocks, raw, etc.).

Quick usage example (ipython notebook) - https://github.com/justheuristic/prefetch_generator/blob/master/example.ipynb

This package contains two objects:
 - The Class     `BackgroundGenerator(generator [,max_prefetch=1])`
 - The decorator `@prefetch([max_prefetch=1])`

the usage is either

#for item in BackgroundGenerator(my_generator):
#    do_stuff(item)

or

#@prefetch()
#def my_generator(some_param):
#    while True:
#        X = read_heavy_file()
#        y = wget_from_cornhub()
#        do_pretty_much_anything(some_param)
#        yield X, y


More details are written in the `BackgroundGenerator` doc:
See `help(BackgroundGenerator)`
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/justheuristic/prefetch_generator",
    "name": "prefetch-generator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "background generator,prefetch generator,parallel generator,prefetch,background,deep learning,theano,tensorflow,lasagne,blocks",
    "author": "",
    "author_email": "justheuristic@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/28/cf/f6c148289fd87832e9f20428b7e842921efac5313cb3ac5920a424543760/prefetch_generator-1.0.3.tar.gz",
    "platform": null,
    "description": "Based on http://stackoverflow.com/questions/7323664/python-generator-pre-fetch\n\nThis is a single-function package that makes it possible to transform any generator into a `BackgroundGenerator` which computes any number of elements from the generator ahead, in a background thread.\n\nIt is quite lightweight, but not entirely weightless.\n\nThe `BackgroundGenerator` is most useful when you have a GIL releasing task which might take a long time to complete (e.g. Disk I/O, Web Requests, pure C functions, GPU processing, ...), and another task which takes a similar amount of time, but is dependent on the results of the first task (e.g. Computationally intensive processing of data loaded from disk).\n\nNormally these two tasks will constantly wait for one another to finish. If you make one of these tasks a `BackgroundGenerator` (see examples below), they will work in parallel, potentially saving up to 50% of execution time (definitely less in practice).\n\nWe personally use the `BackgroundGenerator` when iterating over minibatches of data for deep learning with tensorflow and theano ( lasagne, blocks, raw, etc.).\n\nQuick usage example (ipython notebook) - https://github.com/justheuristic/prefetch_generator/blob/master/example.ipynb\n\nThis package contains two objects:\n - The Class     `BackgroundGenerator(generator [,max_prefetch=1])`\n - The decorator `@prefetch([max_prefetch=1])`\n\nthe usage is either\n\n#for item in BackgroundGenerator(my_generator):\n#    do_stuff(item)\n\nor\n\n#@prefetch()\n#def my_generator(some_param):\n#    while True:\n#        X = read_heavy_file()\n#        y = wget_from_cornhub()\n#        do_pretty_much_anything(some_param)\n#        yield X, y\n\n\nMore details are written in the `BackgroundGenerator` doc:\nSee `help(BackgroundGenerator)`",
    "bugtrack_url": null,
    "license": "The Unlicense",
    "summary": "a simple tool to compute arbitrary generator in a background thread",
    "version": "1.0.3",
    "split_keywords": [
        "background generator",
        "prefetch generator",
        "parallel generator",
        "prefetch",
        "background",
        "deep learning",
        "theano",
        "tensorflow",
        "lasagne",
        "blocks"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "28cff6c148289fd87832e9f20428b7e842921efac5313cb3ac5920a424543760",
                "md5": "9a9956a6ced74f63cd7c55db4038d32d",
                "sha256": "cefabd51c7ff3cdc1c885e22d287592219fe1ca25623322806370a0ce9acd32b"
            },
            "downloads": -1,
            "filename": "prefetch_generator-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "9a9956a6ced74f63cd7c55db4038d32d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4592,
            "upload_time": "2022-11-19T14:38:34",
            "upload_time_iso_8601": "2022-11-19T14:38:34.210429Z",
            "url": "https://files.pythonhosted.org/packages/28/cf/f6c148289fd87832e9f20428b7e842921efac5313cb3ac5920a424543760/prefetch_generator-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-11-19 14:38:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "justheuristic",
    "github_project": "prefetch_generator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "prefetch-generator"
}
        
Elapsed time: 0.02613s