# 列表并行
列表并行是一个用于并行处理列表任务的工具。它提供了一种简单而高效的方式来执行并行任务,针对给定的列表进行处理。
## 功能
- 并行执行任务:利用多线程或多进程的方式,并行处理给定的列表任务。
- 灵活的任务定义:可以自定义任务函数,根据具体需求对列表中的每个元素进行处理。
- 可配置的并行度:可以根据系统资源和任务复杂度,灵活地调整并行度。
- 进度跟踪和错误处理:提供进度跟踪功能,以及错误处理和日志记录,方便调试和排查问题。
## 安装
列表并行可以通过以下步骤进行安装:
1. 从源码安装:
```shell
git clone https://github.com/timekettle/mjob.git
cd mjob
python -m pip install ./
```
2. 从pypi安装
```shell
pip install mjob
```
## 使用示例
1. 首先自行准备`test.list`(要处理的文件列表)
```shell
# 文件夹结构
data
├── 001.txt
├── 002.txt
├── 003
│ └── 003.txt
└── 004
└── 004.txt
# 生成文件列表
find data -name "*.txt" >test.list
```
2. 指定不同的`task`,为文件列表执行不同的操作
```shell
# 查看参数说明
mjob --help
# 通过给定的test.list文件,快速复制到包含 data_new 的新目录中
mjob --task copy \
--file_list test.list \
--old_dir data \
--new_dir data_new \
--nj 4
# 通过给定的test.list文件,创建软连接到包含 data_new 的新目录中
mjob --task link \
--file_list test.list \
--old_dir data \
--new_dir data_new \
--nj 4
# 通过给定的test.list音频文件列表,快速音频重采样到16k,保存到到包含 data_new 的新目录中
mjob --task resample \
--file_list test.list \
--old_dir data \
--new_dir data_new \
--nj 4
# 通过给定的test.list文件,快速删除文件
mjob --task delete \
--file_list test.list \
--nj 4
# 通过给定的test.list文件,快速展示所有文件
mjob --task show \
--file_list test.list \
--nj 4
# 通过给定的test.list文件,快速执行命令(确保命令的合法性)
mjob --task run \
--file_list test.list \
--nj 4
# 以上任务默认使用多进程方式运行,添加 --thread 参数使用多线程方式运行
mjob --task copy \
--file_list test.list \
--old_dir data \
--new_dir data_new \
--nj 4 \
--thread
```
## 贡献
如果你发现了任何问题或有改进的建议,欢迎提出issue或提交pull request。我们非常欢迎贡献者为该项目做出贡献。
Raw data
{
"_id": null,
"home_page": "https://github.com/timekettle/mjob",
"name": "mjob",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "multi",
"author": "sirui.li",
"author_email": "sirui.li@timekettle.co",
"download_url": "https://files.pythonhosted.org/packages/3c/e3/ca88205674e21528179f8fa584ed276a8f4a93eaf7f572d6ba253579ca13/mjob-1.2.0.tar.gz",
"platform": null,
"description": "# \u5217\u8868\u5e76\u884c\n\n\u5217\u8868\u5e76\u884c\u662f\u4e00\u4e2a\u7528\u4e8e\u5e76\u884c\u5904\u7406\u5217\u8868\u4efb\u52a1\u7684\u5de5\u5177\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5355\u800c\u9ad8\u6548\u7684\u65b9\u5f0f\u6765\u6267\u884c\u5e76\u884c\u4efb\u52a1\uff0c\u9488\u5bf9\u7ed9\u5b9a\u7684\u5217\u8868\u8fdb\u884c\u5904\u7406\u3002\n\n## \u529f\u80fd\n\n- \u5e76\u884c\u6267\u884c\u4efb\u52a1\uff1a\u5229\u7528\u591a\u7ebf\u7a0b\u6216\u591a\u8fdb\u7a0b\u7684\u65b9\u5f0f\uff0c\u5e76\u884c\u5904\u7406\u7ed9\u5b9a\u7684\u5217\u8868\u4efb\u52a1\u3002\n- \u7075\u6d3b\u7684\u4efb\u52a1\u5b9a\u4e49\uff1a\u53ef\u4ee5\u81ea\u5b9a\u4e49\u4efb\u52a1\u51fd\u6570\uff0c\u6839\u636e\u5177\u4f53\u9700\u6c42\u5bf9\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u8fdb\u884c\u5904\u7406\u3002\n- \u53ef\u914d\u7f6e\u7684\u5e76\u884c\u5ea6\uff1a\u53ef\u4ee5\u6839\u636e\u7cfb\u7edf\u8d44\u6e90\u548c\u4efb\u52a1\u590d\u6742\u5ea6\uff0c\u7075\u6d3b\u5730\u8c03\u6574\u5e76\u884c\u5ea6\u3002\n- \u8fdb\u5ea6\u8ddf\u8e2a\u548c\u9519\u8bef\u5904\u7406\uff1a\u63d0\u4f9b\u8fdb\u5ea6\u8ddf\u8e2a\u529f\u80fd\uff0c\u4ee5\u53ca\u9519\u8bef\u5904\u7406\u548c\u65e5\u5fd7\u8bb0\u5f55\uff0c\u65b9\u4fbf\u8c03\u8bd5\u548c\u6392\u67e5\u95ee\u9898\u3002\n\n## \u5b89\u88c5\n\n\u5217\u8868\u5e76\u884c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u5b89\u88c5\uff1a\n\n1. \u4ece\u6e90\u7801\u5b89\u88c5\uff1a\n\n```shell\ngit clone https://github.com/timekettle/mjob.git \ncd mjob\npython -m pip install ./\n```\n\n2. \u4ecepypi\u5b89\u88c5\n\n```shell\npip install mjob\n```\n\n## \u4f7f\u7528\u793a\u4f8b\n1. \u9996\u5148\u81ea\u884c\u51c6\u5907`test.list`(\u8981\u5904\u7406\u7684\u6587\u4ef6\u5217\u8868)\n```shell\n# \u6587\u4ef6\u5939\u7ed3\u6784\ndata\n\u251c\u2500\u2500 001.txt\n\u251c\u2500\u2500 002.txt\n\u251c\u2500\u2500 003\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 003.txt\n\u2514\u2500\u2500 004\n \u2514\u2500\u2500 004.txt\n\n# \u751f\u6210\u6587\u4ef6\u5217\u8868\nfind data -name \"*.txt\" >test.list\n```\n2. \u6307\u5b9a\u4e0d\u540c\u7684`task`\uff0c\u4e3a\u6587\u4ef6\u5217\u8868\u6267\u884c\u4e0d\u540c\u7684\u64cd\u4f5c\n```shell\n# \u67e5\u770b\u53c2\u6570\u8bf4\u660e\nmjob --help\n\n# \u901a\u8fc7\u7ed9\u5b9a\u7684test.list\u6587\u4ef6\uff0c\u5feb\u901f\u590d\u5236\u5230\u5305\u542b data_new \u7684\u65b0\u76ee\u5f55\u4e2d\nmjob --task copy \\\n--file_list test.list \\\n--old_dir data \\\n--new_dir data_new \\\n--nj 4\n\n# \u901a\u8fc7\u7ed9\u5b9a\u7684test.list\u6587\u4ef6\uff0c\u521b\u5efa\u8f6f\u8fde\u63a5\u5230\u5305\u542b data_new \u7684\u65b0\u76ee\u5f55\u4e2d\nmjob --task link \\\n--file_list test.list \\\n--old_dir data \\\n--new_dir data_new \\\n--nj 4\n\n# \u901a\u8fc7\u7ed9\u5b9a\u7684test.list\u97f3\u9891\u6587\u4ef6\u5217\u8868\uff0c\u5feb\u901f\u97f3\u9891\u91cd\u91c7\u6837\u523016k\uff0c\u4fdd\u5b58\u5230\u5230\u5305\u542b data_new \u7684\u65b0\u76ee\u5f55\u4e2d\nmjob --task resample \\\n--file_list test.list \\\n--old_dir data \\\n--new_dir data_new \\\n--nj 4\n\n# \u901a\u8fc7\u7ed9\u5b9a\u7684test.list\u6587\u4ef6\uff0c\u5feb\u901f\u5220\u9664\u6587\u4ef6\nmjob --task delete \\\n--file_list test.list \\\n--nj 4\n\n# \u901a\u8fc7\u7ed9\u5b9a\u7684test.list\u6587\u4ef6\uff0c\u5feb\u901f\u5c55\u793a\u6240\u6709\u6587\u4ef6\nmjob --task show \\\n--file_list test.list \\\n--nj 4\n\n# \u901a\u8fc7\u7ed9\u5b9a\u7684test.list\u6587\u4ef6\uff0c\u5feb\u901f\u6267\u884c\u547d\u4ee4\uff08\u786e\u4fdd\u547d\u4ee4\u7684\u5408\u6cd5\u6027\uff09\nmjob --task run \\\n--file_list test.list \\\n--nj 4\n\n# \u4ee5\u4e0a\u4efb\u52a1\u9ed8\u8ba4\u4f7f\u7528\u591a\u8fdb\u7a0b\u65b9\u5f0f\u8fd0\u884c\uff0c\u6dfb\u52a0 --thread \u53c2\u6570\u4f7f\u7528\u591a\u7ebf\u7a0b\u65b9\u5f0f\u8fd0\u884c\nmjob --task copy \\\n--file_list test.list \\\n--old_dir data \\\n--new_dir data_new \\\n--nj 4 \\\n--thread\n```\n\n## \u8d21\u732e\n\n\u5982\u679c\u4f60\u53d1\u73b0\u4e86\u4efb\u4f55\u95ee\u9898\u6216\u6709\u6539\u8fdb\u7684\u5efa\u8bae\uff0c\u6b22\u8fce\u63d0\u51faissue\u6216\u63d0\u4ea4pull request\u3002\u6211\u4eec\u975e\u5e38\u6b22\u8fce\u8d21\u732e\u8005\u4e3a\u8be5\u9879\u76ee\u505a\u51fa\u8d21\u732e\u3002\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Perform parallel tasks based on a given file list",
"version": "1.2.0",
"project_urls": {
"Homepage": "https://github.com/timekettle/mjob"
},
"split_keywords": [
"multi"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a8383cd0771504eeaa528b8dc3e611ad118723f03d417f046f8e18205b81d09e",
"md5": "005284fa6509c407902feb60737f6bba",
"sha256": "141ab2aedbb2f9b727a7618e6b44fa65cb8f6712fdbba8019705bfa4fa7af3d9"
},
"downloads": -1,
"filename": "mjob-1.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "005284fa6509c407902feb60737f6bba",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5199,
"upload_time": "2024-06-17T10:30:05",
"upload_time_iso_8601": "2024-06-17T10:30:05.073631Z",
"url": "https://files.pythonhosted.org/packages/a8/38/3cd0771504eeaa528b8dc3e611ad118723f03d417f046f8e18205b81d09e/mjob-1.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3ce3ca88205674e21528179f8fa584ed276a8f4a93eaf7f572d6ba253579ca13",
"md5": "bd4208eab86e79e16468329acfca3e62",
"sha256": "607d1a02aca4a0516111bafcd6bebf8cd5556cf649a36ee49389d488637a23fd"
},
"downloads": -1,
"filename": "mjob-1.2.0.tar.gz",
"has_sig": false,
"md5_digest": "bd4208eab86e79e16468329acfca3e62",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4827,
"upload_time": "2024-06-17T10:30:06",
"upload_time_iso_8601": "2024-06-17T10:30:06.789171Z",
"url": "https://files.pythonhosted.org/packages/3c/e3/ca88205674e21528179f8fa584ed276a8f4a93eaf7f572d6ba253579ca13/mjob-1.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-17 10:30:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "timekettle",
"github_project": "mjob",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "mjob"
}