我是靠谱客的博主 跳跃嚓茶,这篇文章主要介绍python后台运行怎么操作_如何使用Python在后台运行方法,现在分享给大家,希望可以做个参考。

我试图在python(一个由aws服务器的消息不断更新的类)的后台运行一个方法,并将其用作模板。问题是,我不能让它打印('checkpoint')或print('bye')。它一直在跑。为什么?在import threading

import time

class ThreadingExample(object):

""" Threading example class

The run() method will be started and it will run in the background

until the application exits.

"""

def __init__(self, interval=1):

""" Constructor

:type interval: int

:param interval: Check interval, in seconds

"""

self.interval = interval

thread = threading.Thread(target=self.run, args=())

thread.daemon = True # Daemonize thread

thread.start() # Start the execution

def run(self):

""" Method that runs forever """

while True:

# Do something

print('Doing something imporant in the background')

time.sleep(self.interval)

example = ThreadingExample()

time.sleep(3)

print('Checkpoint')

time.sleep(2)

print('Bye')

编辑:我忘了提到我在Ubuntu14.04LTS64位上使用的是Python2.7.6

最后

以上就是跳跃嚓茶最近收集整理的关于python后台运行怎么操作_如何使用Python在后台运行方法的全部内容,更多相关python后台运行怎么操作_如何使用Python在后台运行方法内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部