【脚本语言系列】关于Python进程线程管理系统模块,你需要知道的事
来源:互联网 发布:剑网3莫雨捏脸数据 编辑:程序博客网 时间:2024/05/18 00:24
如何使用Python管理进程线程
进程的运行环境
# -*- coding:utf-8 -*-import ospath = os.environ.get("PATH")print path
C:\Python27\;C:\Python27\Scripts;C:\Python35\;C:\Python35\Scripts\;C:\Windows\system32;C:\Windows
# -*- coding:utf-8 -*-import osfor key in os.environ.keys(): print key, "\t", os.environ[key]
PATH C:\Python27\;C:\Python27\Scripts;C:\Python35\;C:\Python35\Scripts\;C:\Windows\system32;C:\WindowsSYSTEMROOT C:\WindowsSESSIONNAME ConsolePATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYWWINDIR C:\WindowsHOMEDRIVE C:
创建进程
- system函数(调用cmd后,返还控制权)
# -*- coding:utf-8 -*-import os# create the process with "system"print os.system("dir")
- exec函数族(执行命令后,接管控制权)
# -*- coding:utf-8 -*-import os# create the process with "os.execl"notepad = "C:\\Windows\\notepad.exe"os.execl(notepad,"newfile1.txt")notepad = "C:\\Windows\\not_notepad.exe"os.execl(notepad,"newfile2.txt")
终止进程
- return语句
- sys.exit函数
# -*- coding:utf-8 -*-import sys# exit the process with "sys.exit"try: filename = sys.argv[1] print filenameexcept: print "Usage:", sys.argv[0],"filename" sys.exit(1)return 0
-f File "<ipython-input-6-72d5801fa3fc>", line 10 return 0SyntaxError: 'return' outside function
- os.abort函数
# -*- coding:utf-8 -*-import os,sys# exit the process with "sys.exit"try: filename = sys.argv[1] print filenameexcept: print "Usage:", sys.argv[0],"filename" os.abort()return 0
-f File "<ipython-input-5-eefc966778fc>", line 10 return 0SyntaxError: 'return' outside function
什么是进程线程
进程是正在执行的程序,是执行任务的基本单元;
线程是进程的执行单元;多数程序,只需一个主线程。
阅读全文
0 0
- 【脚本语言系列】关于Python进程线程管理系统模块,你需要知道的事
- 【脚本语言系列】关于Python数据库访问专用模块,你需要知道的事
- 【脚本语言系列】关于Python系统管理,你需要知道的事
- 【脚本语言系列】关于Python容器,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化webbrowser模块,你需要知道的事
- 【脚本语言系列】关于Python调试报错,你需要知道的事
- 【脚本语言系列】关于Python开发环境搭建,你需要知道的事
- 【脚本语言系列】关于Python数值计算NumPy, 你需要知道的事
- 【脚本语言系列】关于Python测试工具lettuce, 你需要知道的事
- 【脚本语言系列】关于Python测试工具mock, 你需要知道的事
- 【脚本语言系列】关于Python测试工具unittest, 你需要知道的事
- 【脚本语言系列】关于Python测试工具docstrings, 你需要知道的事
- 【脚本语言系列】关于Python测试工具Pyflakes, 你需要知道的事
- 【脚本语言系列】关于Python测试工具Pylint, 你需要知道的事
- 【脚本语言系列】关于Python性能分析工具timeit, 你需要知道的事
- 【脚本语言系列】关于Python代码分析工具line_profiler,你需要知道的事
- 【脚本语言系列】关于Python游戏工具Pygame,你需要知道的事
- 【脚本语言系列】关于Python机器学习scikits-learn,你需要知道的事
- fusioncharts的XML标签属性
- 用python写一个小型的FTP客户端软件
- java学习(22)--JDBC(二)
- SpringMVC原理
- Leetcode 14. Longest Common Prefix
- 【脚本语言系列】关于Python进程线程管理系统模块,你需要知道的事
- 543. Diameter of Binary Tree
- windows 64位下安装scipy(python2.7)
- 【Android 清单文件下的 Activity各种配置详解】
- RML(Riemann流形学习)
- 实测:一周不更新文章头条号指数会掉多少?
- POJ 1290 Grandpa's Rubik Cube 笔记
- Js作用域与作用域链详解
- 如何在官网下载Spring各个版本的jar包