callpyfile


Namecallpyfile JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/callpyfile
SummaryExecutes python scripts in different environments without writing temp files to disk, it can pass and receive any type of variable, multiprocessing can be executed from everywhere, not only at top-level
upload_time2023-03-10 02:30:03
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords env dill pickle multiprocessing subprocess
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Executes python scripts in different environments without writing temp files to disk, it can pass and receive any variable, multiprocessing can be executed from everywhere, not only at top-level



## pip install callpyfile





```python

# Create a file called callc1.py

import sys

from callpyfile import run_py_file  # use this function to call the pyfile

from a_cv_imwrite_imread_plus import open_image_in_cv

# an example with OpenCV

pics = [

    "https://github.com/hansalemaos/screenshots/raw/main/gimages/elephant.png",

    "https://github.com/hansalemaos/screenshots/raw/main/gimages/dl.png",

    "https://github.com/hansalemaos/screenshots/raw/main/gimages/house.png",

]

allpics = []

allpics_ = [open_image_in_cv(x) for x in pics]

for p in range(100):

    allpics.extend(allpics_)





# Execute the py file

resu = run_py_file(

    variables={

        "imagelist": allpics

    },  # The keys will be the global variables in the called pyfile

    pyfile=r"C:\Users\Gamer\anaconda3\envs\dfdir\callc2.py",  # The pyfile

    activate_env_command="",  # if you want to activate another environment, you can pass something like this (Anaconda): activate_env_command = ['activate.bat', 'otherenv']

    pythonexe=sys.executable,  # python.exe from your active environment

    raise_exception=False,  # if raise_exception is False, the function returns None if an Exception occurs during the Execution

)

```







```python

# Create another file called callc2.py



import time

import cv2

from pathos.multiprocessing import ProcessingPool as Pool  # By the way: good stuff

import numpy as np

from callpyfile import to_stdout  # import the decorator





# Some CV stuff

def do_cv2_stuff(img):

    kernel = np.ones((5, 5), np.float32) / 25

    dst = cv2.filter2D(img, -1, kernel)

    return dst





@to_stdout(kill_if_exception=True) # optional, kills the process using os._exit()

def exemu():

    pool = Pool(nodes=5)

    res = pool.amap(

        do_cv2_stuff, imagelist

    )  # imagelist is not defined yet, but it doesn't matter because the decorator will create global variables from the dict you'have passed: {"imagelist": allpics},

    while not res.ready():

        time.sleep(0.001)

    allb = res.get()

    return allb





if __name__ == "__main__":

    exemu()

```







```python

# Run  callc1.py



print(allpics[0][:1])

[[[255 255 255]

  [255 255 255]

  [255 255 255]

  ...

  [ 54  53  50]

  [ 57  55  52]

  [ 59  57  54]]]



print(resu[0][:1])

[[[255 255 255]

  [255 255 255]

  [255 255 255]

  ...

  [ 59  58  55]

  [ 56  54  51]

  [ 56  55  52]]]

```




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/callpyfile",
    "name": "callpyfile",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "env,dill,pickle,multiprocessing,subprocess",
    "author": "Johannes Fischer",
    "author_email": "<aulasparticularesdealemaosp@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/3e/a2/cf15b733dd53dbabb420fadbdc9a23a9c7340183ee60f2a503c2fd10b841/callpyfile-0.10.tar.gz",
    "platform": null,
    "description": "\n# Executes python scripts in different environments without writing temp files to disk, it can pass and receive any variable, multiprocessing can be executed from everywhere, not only at top-level\n\n\n\n## pip install callpyfile\n\n\n\n\n\n```python\n\n# Create a file called callc1.py\n\nimport sys\n\nfrom callpyfile import run_py_file  # use this function to call the pyfile\n\nfrom a_cv_imwrite_imread_plus import open_image_in_cv\n\n# an example with OpenCV\n\npics = [\n\n    \"https://github.com/hansalemaos/screenshots/raw/main/gimages/elephant.png\",\n\n    \"https://github.com/hansalemaos/screenshots/raw/main/gimages/dl.png\",\n\n    \"https://github.com/hansalemaos/screenshots/raw/main/gimages/house.png\",\n\n]\n\nallpics = []\n\nallpics_ = [open_image_in_cv(x) for x in pics]\n\nfor p in range(100):\n\n    allpics.extend(allpics_)\n\n\n\n\n\n# Execute the py file\n\nresu = run_py_file(\n\n    variables={\n\n        \"imagelist\": allpics\n\n    },  # The keys will be the global variables in the called pyfile\n\n    pyfile=r\"C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\callc2.py\",  # The pyfile\n\n    activate_env_command=\"\",  # if you want to activate another environment, you can pass something like this (Anaconda): activate_env_command = ['activate.bat', 'otherenv']\n\n    pythonexe=sys.executable,  # python.exe from your active environment\n\n    raise_exception=False,  # if raise_exception is False, the function returns None if an Exception occurs during the Execution\n\n)\n\n```\n\n\n\n\n\n\n\n```python\n\n# Create another file called callc2.py\n\n\n\nimport time\n\nimport cv2\n\nfrom pathos.multiprocessing import ProcessingPool as Pool  # By the way: good stuff\n\nimport numpy as np\n\nfrom callpyfile import to_stdout  # import the decorator\n\n\n\n\n\n# Some CV stuff\n\ndef do_cv2_stuff(img):\n\n    kernel = np.ones((5, 5), np.float32) / 25\n\n    dst = cv2.filter2D(img, -1, kernel)\n\n    return dst\n\n\n\n\n\n@to_stdout(kill_if_exception=True) # optional, kills the process using os._exit()\n\ndef exemu():\n\n    pool = Pool(nodes=5)\n\n    res = pool.amap(\n\n        do_cv2_stuff, imagelist\n\n    )  # imagelist is not defined yet, but it doesn't matter because the decorator will create global variables from the dict you'have passed: {\"imagelist\": allpics},\n\n    while not res.ready():\n\n        time.sleep(0.001)\n\n    allb = res.get()\n\n    return allb\n\n\n\n\n\nif __name__ == \"__main__\":\n\n    exemu()\n\n```\n\n\n\n\n\n\n\n```python\n\n# Run  callc1.py\n\n\n\nprint(allpics[0][:1])\n\n[[[255 255 255]\n\n  [255 255 255]\n\n  [255 255 255]\n\n  ...\n\n  [ 54  53  50]\n\n  [ 57  55  52]\n\n  [ 59  57  54]]]\n\n\n\nprint(resu[0][:1])\n\n[[[255 255 255]\n\n  [255 255 255]\n\n  [255 255 255]\n\n  ...\n\n  [ 59  58  55]\n\n  [ 56  54  51]\n\n  [ 56  55  52]]]\n\n```\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Executes python scripts in different environments without writing temp files to disk, it can pass and receive any type of variable, multiprocessing can be executed from everywhere, not only at top-level",
    "version": "0.10",
    "split_keywords": [
        "env",
        "dill",
        "pickle",
        "multiprocessing",
        "subprocess"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "776b4ba65179e6cbb9018278a7b0df7b11c365b2845b5bafa32b795c58d05748",
                "md5": "4115c63c8351b0fefcd54b698b9c30b1",
                "sha256": "8d610b9f8fc47f2651d2d3c2f015ee9b25c7139a5b98eaa9c3555bcae7e62e95"
            },
            "downloads": -1,
            "filename": "callpyfile-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4115c63c8351b0fefcd54b698b9c30b1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6796,
            "upload_time": "2023-03-10T02:30:02",
            "upload_time_iso_8601": "2023-03-10T02:30:02.283988Z",
            "url": "https://files.pythonhosted.org/packages/77/6b/4ba65179e6cbb9018278a7b0df7b11c365b2845b5bafa32b795c58d05748/callpyfile-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3ea2cf15b733dd53dbabb420fadbdc9a23a9c7340183ee60f2a503c2fd10b841",
                "md5": "1e6343c4238a6bc924724d50fcf34638",
                "sha256": "c82dbe96b9ab9969d30c4d98c0cd4bc879e627ae5512eecc52911e4d032daeda"
            },
            "downloads": -1,
            "filename": "callpyfile-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "1e6343c4238a6bc924724d50fcf34638",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4893,
            "upload_time": "2023-03-10T02:30:03",
            "upload_time_iso_8601": "2023-03-10T02:30:03.826502Z",
            "url": "https://files.pythonhosted.org/packages/3e/a2/cf15b733dd53dbabb420fadbdc9a23a9c7340183ee60f2a503c2fd10b841/callpyfile-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-10 02:30:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "hansalemaos",
    "github_project": "callpyfile",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "callpyfile"
}
        
Elapsed time: 0.05132s