使用多线程的方式打印 Hello World
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用多线程的方式打印 Hello World相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env python #encoding:utf8 import thread def hello(): for i in xrange(5): w_lock.acquire() print ‘Hello‘, h_lock.release() def world(): for i in xrange(5): h_lock.acquire() print ‘World‘ w_lock.release() lock.release() lock = thread.allocate_lock() lock.acquire() h_lock = thread.allocate_lock() w_lock = thread.allocate_lock() h_lock.acquire() thread.start_new_thread(hello, ()) thread.start_new_thread(world, ()) while lock.locked(): pass
[[email protected] ~]# python 1.py Hello World Hello World Hello World Hello World Hello World
以上是关于使用多线程的方式打印 Hello World的主要内容,如果未能解决你的问题,请参考以下文章
为啥这段代码使用 Math.pow 打印“HELLO WORLD”?