Пример #1
0
def sendMess():
    # friendA = bot.friends().search('王壮才')[0]
    # friendA.send("222")

    print(bot.friends)
    t = Timer(1, sendMess)
    # 开始线程
    t.start()
    t.getName()
    print(t.getName())
Пример #2
0
def timerThreads2():
    t1 = Timer(interval=5, function=timerThreadFunc)
    t1.setName('t1')
    t2 = Timer(interval=5, function=timerThreadFunc)
    t2.setName('t2')

    logging.debug('starting timers...')
    t1.start()
    t2.start()

    logging.debug('waiting before canceling %s', t2.getName())
    time.sleep(2)
    logging.debug('canceling %s', t2.getName())
    print('before cancel t2.is_alive() = ', t2.is_alive())
    t2.cancel()
    time.sleep(2)
    print('after cancel t2.is_alive() = ', t2.is_alive())

    t1.join()
    t2.join()

    logging.debug('done')
def create_delta_thread(secs, filename, dToRun, dNow, hour, minutes,
                        thread_name):
    t = Timer(secs, delta_utils.perform_database_update, args=(filename, ))
    t.start()
    if thread_name == None:
        thread_name = uuid.uuid4()
    t.setName(thread_name)
    tname = t.getName()
    print("Thread name of scheduled thread is " + str(tname))

    if dToRun is None:
        dToRun = dNow

    file = open(constants.FILE_LOCATION_PATH + constants.THREADS_TO_RUN, 'w')
    file.write(tname + ":" + filename + ":" + str(dToRun) + ":" + str(hour) +
               ":" + str(minutes))
    file.close()
    return tname
Пример #4
0
def NamedTimer(*args,**kwargs):
    t = Timer(*args,**kwargs)
    t.setDaemon(True)
    t.setName("NamedTimer"+t.getName())
    return t
def NamedTimer(*args, **kwargs):
    t = Timer(*args, **kwargs)
    t.setDaemon(True)
    t.setName('NamedTimer' + t.getName())
    return t
Пример #6
0
basicConfig(level=DEBUG, format="(%(threadName)s) %(message)s",)

def myThread():
    debug("myThread running")

thread1 = Timer(3, myThread)
thread1.setName("Thread1")
thread2 = Timer(3, myThread)
thread2.setName("Thread2")

debug("starting timers")
thread1.start()
thread2.start()

debug("waiting before canceling %s", thread2.getName())
sleep(2)
debug("canceling %s", thread2.getName())
thread2.cancel()

print("Main thread is done")

##################################################
#
#     $ timerthreads.py
#     (MainThread) starting timers
#     (MainThread) waiting before canceling Thread2
#     (MainThread) canceling Thread2
#     Main thread is done
#     (Thread1) myThread running
#
Пример #7
0

def myThread():
    debug("myThread running")


thread1 = Timer(3, myThread)
thread1.setName("Thread1")
thread2 = Timer(3, myThread)
thread2.setName("Thread2")

debug("starting timers")
thread1.start()
thread2.start()

debug("waiting before canceling %s", thread2.getName())
sleep(2)
debug("canceling %s", thread2.getName())
thread2.cancel()

print "Main thread is done"

##################################################
#
#     $ timerthreads.py
#     (MainThread) starting timers
#     (MainThread) waiting before canceling Thread2
#     (MainThread) canceling Thread2
#     Main thread is done
#     (Thread1) myThread running
#