当前位置: 首页>>代码示例>>Python>>正文


Python Thread.isDaemon方法代码示例

本文整理汇总了Python中threading.Thread.isDaemon方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.isDaemon方法的具体用法?Python Thread.isDaemon怎么用?Python Thread.isDaemon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在threading.Thread的用法示例。


在下文中一共展示了Thread.isDaemon方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import isDaemon [as 别名]
def main():
    file = open("file.txt")
    q = Queue()
    t = Thread(target=enq, args=(file,q))
    t.isDaemon()
    t.start()
    doSomethingWithData()
开发者ID:emmanuj,项目名称:gogo,代码行数:9,代码来源:hello.py

示例2: threadedConnection

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import isDaemon [as 别名]
class threadedConnection(baseConnection):
  def setup(self,config,name="ThreadedConnection"):
    super(threadedConnection,self).setup(config,name)
    self.thread = Thread(target=self.run,name=name)
    self.keep_running = True

  def join(self,*args,**kwargs):
    self.thread.join(*args,**kwargs)

  def run(self):
    raise NotImplementedError()

  def start(self):
    self.thread.start()
    return True

  def wake(self):
    return True

  def stop(self,wait=True): # API, runs outside of thread
    self.keep_running = False
    self.wake()
    if wait and not self.thread.isDaemon() and currentThread() != self.thread:
      self.join()
    return True
开发者ID:jvantuyl,项目名称:vertebra-py,代码行数:27,代码来源:base.py

示例3: Foo

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import isDaemon [as 别名]
"""
import os, sys
import time
from threading import  Thread

def Foo(arg,arg2):
    for i in range(30):
        print i
        time.sleep(1)

print 'before'
t1 = Thread(target=Foo,args=(1,2,))
t1.setDaemon(True)
t1.start()
t1.join(5)  #主线程到达join,直到子线程结束才继续主线程。默认不超时,如果超过5s,超时后主线程不等待
print t1.getName()
#t1.setName('testthread')
print t1.isDaemon()  #False 等待子线程完成才结束主线程。True 主线程结束就退出,不等待子线程.是否守护
print t1.isAlive()

print 'after'
print 'after'
print 'after'
print 'after end'
time.sleep(10)





开发者ID:wangweislk,项目名称:python_oldboy,代码行数:27,代码来源:threadingtest.py

示例4: print

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import isDaemon [as 别名]
    print " Global Location: %s" % vehicle.location.global_frame

    vehicle.simple_goto(LocationGlobalRelative(myLat,myLon,alt))
    time.sleep(3)
    print " Global Location: %s" % vehicle.location.global_frame

    vehicle.close()
    run = False
    print("done")

def runB():
    global run
    while run:
        #gpsData[time.time()] = str(vehicle.location.global_frame)
        gpsData[datetime.datetime.fromtimestamp(int(time.time())).strftime('%Y-%m-%d %H:%M:%S')] = str(vehicle.location.global_frame)
        time.sleep(.1)
    with open('gpsTimestamps', 'w') as f:
        json.dump(gpsData, f)

if __name__ == "__main__":
    t1 = Thread(target = runA)
    t2 = Thread(target = runB)
    t1.isDaemon()
    t2.isDaemon()
    t1.start()
    t2.start()
    t1.join()
    t2.join()


开发者ID:nlurski,项目名称:summersdrspectrum,代码行数:30,代码来源:droneHexMulti.py

示例5: PickleAwareThread

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import isDaemon [as 别名]
class PickleAwareThread (object):
    __metaclass__ = ClassInfoMetaclass

    def __init__(self, group = None, target = None, name = None, args = (), kwargs = {}):
        self.__thread = Thread(group = group, target = self.__run_thread, name = name, args = args, kwargs = kwargs)
        self.__group = group
        self.__target = target
        self.__name = self.__thread.getName()
        self.__args = args
        self.__kwargs = kwargs
        self.__is_daemon = self.__thread.isDaemon()
        self.__started = False
        self.__stopped = False

    def __pickle_data(self, data):
        del data[getattrname(self.__clsname, "__thread")]

    def __unpickle_data(self, data):
        if not self.__started:
            self.__thread = Thread(group = self.__group, target = self.__run_thread, name = self.__name, args = self.__args,
                kwargs = self.__kwargs)
        else:
            self.__thread = None

    def __getstate__(self):
        return pickle_data(self)

    def __setstate__(self, data):
        unpickle_data(self, data)

    def start(self):
        if self.__thread:
            self.__started = True
            self.__thread.start()
        else:
            assert False, "thread already started"

    def __run_thread(self):
        self.__started = True
        try:
            self.run()
        finally:
            self.__stopped = True

    def run(self):
        if self.__target:
            self.__target(*self.__args, **self.__kwargs)

    def join(self, timeout = None):
        if self.__thread:
            self.__thread.join(timeout)
        elif not self.__stopped:
            raise ThreadPickledAliveException

    def getName(self):
        return self.__name

    def setName(self, name):
        self.__name = name
        if self.__thread:
            self.__thread.setName(name)

    def isAlive(self):
        if self.__thread:
            return self.__thread.isAlive()
        elif self.__stopped:
            return False
        else:
            raise ThreadPickledAliveException

    def isDaemon(self):
        return self.__is_daemon

    def setDaemon(self, daemonic):
        assert not self.__started, "cannot set daemon status of active thread"
        self.__thread.setDaemon(daemonic)
        self.is_daemon = daemonic
开发者ID:ido,项目名称:cobalt,代码行数:79,代码来源:Util.py

示例6: foo

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import isDaemon [as 别名]
#!/usr/bin/env python
# _*_coding:utf-8_*_

from threading import Thread
import time


def foo(arg, v):
    for item in range(100):
        print item
        time.sleep(1)
print 'before'
t1 = Thread(target=foo, args=('test1', 10))
t1.setDaemon(daemonic=True)
t1.start()
t1.join(5)
print '\n---'
print t1.getName()
print t1.isDaemon()
print 'after'
#time.sleep(10)   #当主线程退出后,子线程也随着销毁
开发者ID:jameyang,项目名称:python,代码行数:23,代码来源:threading01.py

示例7: myfunction

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import isDaemon [as 别名]
Created on 2016年4月25日

@author: zhongqiang

Describe: 多线程的实现方式和相关的方法
'''

from threading import Thread
from time import sleep, ctime, sleep


def myfunction(arg):
    for item in range(10):
        print item
        sleep(1)


print "before"
t1 = Thread(target=myfunction, args=('hello',))
print t1.getName()  # Thread-1
print t1.isDaemon()  # 默认为false
# t1.setDaemon(True)  #设置为setDaemon模式

t1.start()
t1.join(timeout=5)

print "after"
print "Over"

sleep(5)
开发者ID:ops-chengdu-zhongqiang,项目名称:studypy,代码行数:32,代码来源:thread_fun01.py


注:本文中的threading.Thread.isDaemon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。