Skip to main content

light_process

Python multiprocessing.Process that does not need to import __main__.

Normally python multiprocessing using the __main__ module to create and initiallize the process. The LightProcess allows you to change what module is used to create and initialize the process. By default the LightProcess uses the module that calls LightProcess.start()

Example

# readme_module.py
import light_process as lp
import multiprocessing as mp


def run():
    print('readme_module')


def run_light_process():
    proc = lp.LightProcess(target=run)
    proc.start()
    proc.join()


def run_multiprocessing():
    proc = mp.Process(target=run)
    proc.start()
    proc.join()

Multiprocessing works by using the __main__ module to import and seutp the environment for multiprocess. Using the multiprocessing.Process requires you to put your multiprocessing code in “if __name__ == ‘__main__’:”. This can be shown in the following example.

# readme_main_multiprocessing.py
import readme_module


print('__main__')


if __name__ == '__main__':
    print("if __name__ == '__main__':")
    readme_module.run_multiprocessing()

# Output:
# __main__
# if __name__ == '__main__':
# __main__
# readme_module
#
# Note:
# '__main__' and 'readme_module' will be printed
# '__main__' will be printed twice, because this module is imported in the other process

The main takeaway form this is that the main module is imported twice and requires you to run you multiprocessing code in the “if __name__ == ‘__main__’:” block.

LightProcess was made to remove __main__ from being imported. I have large applications that use multiprocessing. I do not need to load the entire enviroment for the process. I simply need one small module to be imported and run. The example below shows how you can run the processes in __main__ and how it doesn’t import __main__ in the new process.

# readme_main_light_process.py
import readme_module


print('__main__')


# Do not need "if __name__ == '__main__':"
readme_module.run_light_process()

# Output:
# __main__
# readme_module
#
# Note:
# '__main__' and 'readme_module' will be printed
# '__main__' will only be printed once

Metadata

Release files for light-process 0.0.7

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

Source distribution (sdist)

Source distribution for light-process 0.0.7
File Size Uploaded
light_process-0.0.7.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for light-process 0.0.7
File Interpreter ABI Platform
light_process-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 25.0 kB

Release files / light_process-0.0.7.tar.gz

Download URL light_process-0.0.7.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b5df626a9e2eba406cd62e3c4ff5d2e9d263548c66477796f76b8f40ed68acbc
BLAKE2b-256 checksum
How to use checksums
a906e73eeaabe2b0ae03207cdd99e62f7f084f1aaba77f8c36a09056678477fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.1

Release files / light_process-0.0.7-py3-none-any.whl

Download URL light_process-0.0.7-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b33f9d762d5f90496c3c5dc8599a783eb55808b946c879c9a23d1ea480a650be
BLAKE2b-256 checksum
How to use checksums
c2094a94bbb3fa0ec05eb8a4f67c1f1a41425bd95e2497add86c3a1f004c784f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.1

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.2

2 release files

0.0.1

2 release files

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