# burner_process
`burner_process` is a wrapper that runs a function inside a newly spawned independent process that is **not** child to the main process, handling the function's arguments and returns (via `pickle`) as well as all its dependencies.
Other solutions (such as [this one](https://gist.github.com/schlamar/2311116)) rely on `subprocess` and thus spawn a process that is child to the main process, sharing memory and resources with it. `burner_process` comes in handy when you need to run a function in an isolated environment, as a 'hard' workaround to memory leaks or inside parallel sub-processes, to monitor a specific function's resources usage.
### Limitations
- The function has to be defined in a module different from the main, and the functions's module must not include importing `burner_process` (see example below), which would cause circular imports.
- Both arguments and returns must be **pickleable**<br/>
### Features
- Supporting overlapping/parallel calls<br/>
- Not relying on `subprocess` nor `multiprocessing`<br/>
- Not relying on a queue for the returns<br/>
- Tested on Windows and Linux
## Usage
### Installation
`pip install burner_process`<br/>
### Example
`my_module.py`
```python
def my_function(x):
return x * 2
```
`my_script.py`
```python
from burner_process import processify
from my_module import my_function
my_processified_function = processify(my_function)
my_processified_function(5)
```
```
>> 10
```
### Verbose example
`my_module.py`
```python
def my_function(x):
return x * 2
```
`my_script.py`
```python
from burner_process import processify
from my_module import my_function
my_processified_function = processify(my_function, verbose=True)
my_processified_function(5)
```
```
>> Launching from main process (pid: 20124, parent pid: 10568)
>> Serializing arguments to C:\...\io\3
>> Running inside spawned process (pid: 18976, parent pid: 14584)
>> Serializing outputs to C:\...\io\3
>> 10
```
Raw data
{
"_id": null,
"home_page": "https://github.com/benvigano/burner_process",
"name": "burner-process",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "subprocessing,subprocess,process,multiprocessing,processify,processifier,memory leak",
"author": "benvigano",
"author_email": "beniamino.vigano@protonmail.com",
"download_url": "https://files.pythonhosted.org/packages/69/dc/923acfb21befb5725f1b5dc7780dfd6d2a1401cdb284887dd795787b5993/burner_process-1.0.0.tar.gz",
"platform": null,
"description": "# burner_process\n`burner_process` is a wrapper that runs a function inside a newly spawned independent process that is **not** child to the main process, handling the function's arguments and returns (via `pickle`) as well as all its dependencies.\n\nOther solutions (such as [this one](https://gist.github.com/schlamar/2311116)) rely on `subprocess` and thus spawn a process that is child to the main process, sharing memory and resources with it. `burner_process` comes in handy when you need to run a function in an isolated environment, as a 'hard' workaround to memory leaks or inside parallel sub-processes, to monitor a specific function's resources usage. \n\n### Limitations\n- The function has to be defined in a module different from the main, and the functions's module must not include importing `burner_process` (see example below), which would cause circular imports.\n- Both arguments and returns must be **pickleable**<br/>\n\n### Features\n- Supporting overlapping/parallel calls<br/>\n- Not relying on `subprocess` nor `multiprocessing`<br/>\n- Not relying on a queue for the returns<br/>\n- Tested on Windows and Linux\n\n## Usage\n### Installation\n`pip install burner_process`<br/>\n\n### Example\n`my_module.py`\n```python\ndef my_function(x):\n return x * 2\n```\n\n`my_script.py`\n```python\nfrom burner_process import processify\nfrom my_module import my_function\n\nmy_processified_function = processify(my_function)\nmy_processified_function(5)\n```\n```\n>> 10\n```\n\n### Verbose example\n`my_module.py`\n```python\ndef my_function(x):\n return x * 2\n```\n\n`my_script.py`\n```python\nfrom burner_process import processify\nfrom my_module import my_function\n\nmy_processified_function = processify(my_function, verbose=True)\nmy_processified_function(5)\n```\n```\n>> Launching from main process (pid: 20124, parent pid: 10568)\n>> Serializing arguments to C:\\...\\io\\3\n>> Running inside spawned process (pid: 18976, parent pid: 14584)\n>> Serializing outputs to C:\\...\\io\\3\n>> 10\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A wrapper that runs a function inside a new process, that is not a child of the main process.",
"version": "1.0.0",
"split_keywords": [
"subprocessing",
"subprocess",
"process",
"multiprocessing",
"processify",
"processifier",
"memory leak"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1f9591c321226ffc86a9377a7e0c2f573c0442a5d604077afa26e380850efffe",
"md5": "0397fd97a4cd746ae3ee617d261a43bb",
"sha256": "99b0590fb675dc8e0fc0b05ef72b4441c2124ff6926c8760a0f940e91e7bee88"
},
"downloads": -1,
"filename": "burner_process-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0397fd97a4cd746ae3ee617d261a43bb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5119,
"upload_time": "2023-04-23T16:41:13",
"upload_time_iso_8601": "2023-04-23T16:41:13.494100Z",
"url": "https://files.pythonhosted.org/packages/1f/95/91c321226ffc86a9377a7e0c2f573c0442a5d604077afa26e380850efffe/burner_process-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "69dc923acfb21befb5725f1b5dc7780dfd6d2a1401cdb284887dd795787b5993",
"md5": "78cd2cad8fdcbb8a03a2cacb98e7517c",
"sha256": "8d0ccd00e3e0a7b647a472e9390102653fe51ce828a0b50289198ce4ef9aa00d"
},
"downloads": -1,
"filename": "burner_process-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "78cd2cad8fdcbb8a03a2cacb98e7517c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4100,
"upload_time": "2023-04-23T16:41:15",
"upload_time_iso_8601": "2023-04-23T16:41:15.629765Z",
"url": "https://files.pythonhosted.org/packages/69/dc/923acfb21befb5725f1b5dc7780dfd6d2a1401cdb284887dd795787b5993/burner_process-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-23 16:41:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "benvigano",
"github_project": "burner_process",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "burner-process"
}