擅长:python、mysql、java
<blockquote>
<p>limit the execution of this command.</p>
</blockquote>
<p>从Python2.6+开始,您可以使用<code>multiprocessing</code>模块:</p>
<pre><code>cat <<'PYSTUFF' | python
from multiprocessing import Process
from time import sleep
def task():
while True:
print "oh no!"
sleep(0.5)
p = Process(target=task)
p.start()
p.join(1)
print "*** Aborted"
p.terminate()
PYSTUFF
</code></pre>