Skip to main content

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

# 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

)
# 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()
# 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]]]

Metadata

Release files for callpyfile 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for callpyfile 0.10
File Size Uploaded Provenance Actions
callpyfile-0.10.tar.gz 4.9 kB Without provenance Details for callpyfile-0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for callpyfile 0.10
File Interpreter ABI Platform Actions
callpyfile-0.10-py3-none-any.whl Python 3 none any Details for callpyfile-0.10-py3-none-any.whl

Total release size: 11.7 kB

Release files / callpyfile-0.10.tar.gz

Download URL callpyfile-0.10.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c82dbe96b9ab9969d30c4d98c0cd4bc879e627ae5512eecc52911e4d032daeda
BLAKE2b-256 checksum
How to use checksums
3ea2cf15b733dd53dbabb420fadbdc9a23a9c7340183ee60f2a503c2fd10b841
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / callpyfile-0.10-py3-none-any.whl

Download URL callpyfile-0.10-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d610b9f8fc47f2651d2d3c2f015ee9b25c7139a5b98eaa9c3555bcae7e62e95
BLAKE2b-256 checksum
How to use checksums
776b4ba65179e6cbb9018278a7b0df7b11c365b2845b5bafa32b795c58d05748
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for callpyfile 0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page