python 多进程练习 调用 os.system命令
2024-09-22 05:00:28
import sys
import getopt
import os
import multiprocessing def list_all_file(path):
"""
list all files of a directory
:param path:
:return:
"""
file_list = []
for (path, _, files) in os.walk(path):
for filename in files:
file_list.append(os.path.join(path, filename))
return file_list def process_file(filename, is_black):
suffix = os.path.splitext(filename)[-1][1:]
if suffix != "pcap":
return if is_black:
cmd = "python extract_tls_flow4.py -vr {} -o black/{}.txt >logs/black/{}.log".format(filename, os.path.basename(filename), os.path.basename(filename))
else:
cmd = "python extract_tls_flow4.py -vr {} -o white/{}.txt >logs/white/{}.log".format(filename, os.path.basename(filename), os.path.basename(filename))
os.system(cmd) def process_black_file(filename):
process_file(filename, 1) def process_white_file(filename):
process_file(filename, 0) def process_dir(sample_dir, is_black):
file_list = list_all_file(sample_dir) process_num = 30
pool = multiprocessing.Pool(processes=process_num)
if is_black:
pool.map(process_black_file, file_list)
else:
pool.map(process_white_file, file_list) pool.close()
pool.join()
print("End...........") black_sample_dir = "/opt/data/samples/black_pcap"
white_sample_dir = "/opt/data/samples/white_pcap" process_dir(black_sample_dir, 1)
process_dir(white_sample_dir, 0)
最新文章
- Git 如何只更新项目中某个目录里的文件
- Oracle启动报错ORA-03113解决
- MSSQL 死锁查询
- Babelfish 分类: 哈希 2015-08-04 09:25 2人阅读 评论(0) 收藏
- 有了 Docker,用 JavaScript 框架开发的 Web 站点也能很好地支持网络爬虫的内容抓取
- linux中的livecd、liveDVD和其他安装方式简介
- UITableViewCell高度自适应探索--AutoLayout结合Frame
- 关于Integer类中parseInt()和valueOf()方法的区别以及int和String类性的转换.以及String类valueOf()方法
- 【转】兼容性测试套件(CTS)框架用户手册
- registerWithTouchDispatcher()函数的使用
- Type mismatch: cannot convert from Enumeration&;lt;String&;gt; to Enumeration&;lt;Object&;gt;
- mysql show processlist详解
- 关于在TabBar 中添加按钮,并通过block 或代理在控制器中实现响应
- ue4打包问题的巧妙解决——二分回退大法!
- 简单的调用OpenCV库的Android NDK开发 工具Android Studio
- Oracle profile 使用技巧
- 继续死磕SDRAM控制器
- nnet3配置中的上下文和chunk(块)大小
- IDEA常用快捷键整理(Mac OS X版本)
- 用json获取拉钩网的信息