python 线程学习
彩照
一、学习【1】
# -*- coding: utf-8 -*-
import time
import thread def timer(no, interval):
cnt = 0
while cnt < 10:
print 'Thread (%d), Time is %s \n' % (no, time.ctime())
time.sleep(interval)
cnt += 1
thread.exit_thread() def test():
thread.start_new_thread(timer, (1, 1))
thread.start_new_thread(timer, (2, 2)) if __name__ == '__main__':
test()
while 1:
pass
--------------------------------------
C:\Python27\python.exe E:/Project/actneed411/furion/static/js/shop/test_captcha.py
Thread (1), Time is Mon Aug 29 10:34:24 2016
Thread (2), Time is Mon Aug 29 10:34:24 2016
Thread (1), Time is Mon Aug 29 10:34:25 2016
Thread (2), Time is Mon Aug 29 10:34:26 2016
Thread (1), Time is Mon Aug 29 10:34:26 2016
Thread (1), Time is Mon Aug 29 10:34:27 2016
Thread (1), Time is Mon Aug 29 10:34:28 2016
Thread (2), Time is Mon Aug 29 10:34:28 2016
Thread (1), Time is Mon Aug 29 10:34:29 2016
Thread (2), Time is Mon Aug 29 10:34:30 2016
Thread (1), Time is Mon Aug 29 10:34:30 2016
Thread (1), Time is Mon Aug 29 10:34:31 2016
Thread (2), Time is Mon Aug 29 10:34:32 2016
Thread (1), Time is Mon Aug 29 10:34:32 2016
Thread (1), Time is Mon Aug 29 10:34:33 2016
Thread (2), Time is Mon Aug 29 10:34:34 2016
Thread (2), Time is Mon Aug 29 10:34:36 2016
Thread (2), Time is Mon Aug 29 10:34:38 2016
Thread (2), Time is Mon Aug 29 10:34:40 2016
Thread (2), Time is Mon Aug 29 10:34:42 2016
----------
source:【1】Python多线程学习
python 线程学习的更多相关文章
- Python线程学习
Python3 通过两个标准库 _thread 和 threading 提供对线程的支持. _thread 提供了低级别的.原始的线程以及一个简单的锁,它相比于 threading 模块的功能还是比较 ...
- python 线程 进程 协程 学习
转载自大神博客:http://www.cnblogs.com/aylin/p/5601969.html 仅供学习使用···· python 线程与进程简介 进程与线程的历史 我们都知道计算机是由硬件和 ...
- Python学习——Python线程
一.线程创建 #方法一:将要执行的方法作为参数传给Thread的构造方法 import threading import time def show(arg): time.sleep(2) print ...
- python——线程与多线程进阶
之前我们已经学会如何在代码块中创建新的线程去执行我们要同步执行的多个任务,但是线程的世界远不止如此.接下来,我们要介绍的是整个threading模块.threading基于Java的线程模型设计.锁( ...
- Python 多线程学习(转)
转自:http://www.cnblogs.com/slider/archive/2012/06/20/2556256.html 引言 对于 Python 来说,并不缺少并发选项,其标准库中包括了对线 ...
- Python 线程(threading) 进程(multiprocessing)
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- Day1 Python基础学习
一.编程语言分类 1.简介 机器语言:站在计算机的角度,说计算机能听懂的语言,那就是直接用二进制编程,直接操作硬件 汇编语言:站在计算机的角度,简写的英文标识符取代二进制去编写程序,本质仍然是直接操作 ...
- Day1 Python基础学习——概述、基本数据类型、流程控制
一.Python基础学习 一.编程语言分类 1.简介 机器语言:站在计算机的角度,说计算机能听懂的语言,那就是直接用二进制编程,直接操作硬件 汇编语言:站在计算机的角度,简写的英文标识符取代二进制去编 ...
- Python 系统学习梳理_【All】
Python学习 1. Python学习---Python安装与基础1205 2. Python学习---PyCharm的使用学习 3. Python学习---Python数据类型1206 4. Py ...
随机推荐
- setAlpha方法 设置透明度
public void setAlpha (int x) 其中,参数x为透明度,取值范围为0~255,数值越小越透明.
- QThread
#ifndef MYTHREAD_H #define MYTHREAD_H #include<QThread> class MyThread : public QThread { Q_OB ...
- 《Android 性能测试初探》
移动测试站点推荐: https://testerhome.com/ 专项相关帖子推荐: <Android 性能测试初探>合集 移动无线应用专项测试浅谈 公开课: [腾讯课堂]Testerh ...
- Asp.net导出Excel乱码的解决方法
通过跟踪Asp.net服务器代码,没有乱码,然而导出Excel到浏览器后,打开时出现乱码. 解决方法是添加编码格式的前缀字节码:Response.BinaryWrite(System.Text.Enc ...
- Android shell命令查询ip,网关,DNS
查看所有网络信息 C:\>adb shell root@android:/ # netcfg netcfg ip6tnl0 DOWN 0.0.0.0/0 0x00000080 00:00:00: ...
- 模板 BFS
[模板]BFS #include <stdio.h> #include <string.h> #include <queue> using namespace st ...
- 7.$a = 'abcdef'; 请取出$a的值并打印出第一个字母
echo $a[0]; echo $a{0}; echo chr(ord($a));//先输出$a字符串里的第一个字符的ASCII值 再从指定的 ASCII 值返回字符.
- Access数据库中Sum函数返回空值(Null)时如何设置为0
在完成一个Access表中数据统计时,需要统计指定字段的和,使用到了Sum函数,但统计时发现,指定条件查询统计时有可能返回空值(Null),导致对应字段显示为空白,正常应显示为0.基本思路是在获取记录 ...
- 修改 window.setTimeout,使之可以传递参数和对象参数
/* 功能:修改 window.setTimeout,使之可以传递参数和对象参数 使用方法: setTimeout(回调函数,时间,参数1,,参数n) */ var _setTimeout=setTi ...
- linux中非root用户使用wireshark进行抓包
开始的时候我是在终端中使用sudo 命令打开 wireshark 的,因为如果不这样的话 wireshark 就没法抓包啊.偶尔抓一次包就使用这样的方式提权. 今天使用 wireshark 的时候特意 ...