python 多线程
Posted yuanzhenliu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 多线程相关的知识,希望对你有一定的参考价值。
主程序:main.py
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import article import threading if __name__ == ‘__main__‘: for i in range(10): if i % 2 == 0: t1 = threading.Thread(target = article.sleep, args = ("sleep function",)) t1.start() else: article.publish("publish function")
模块程序:
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import time def sleep(msg): time.sleep(2) print msg def publish(msg): print msg if __name__ == ‘__main__‘: publish("publish") sleep("sleep")
output
publish function publish function publish function publish function publish function sleep functionsleep functionsleep functionsleep function sleep function
以上是关于python 多线程的主要内容,如果未能解决你的问题,请参考以下文章