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)
| File | Size | Uploaded | |
|---|---|---|---|
| light_process-0.0.7.tar.gz | 6.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|