-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.py
More file actions
34 lines (28 loc) · 1009 Bytes
/
demo.py
File metadata and controls
34 lines (28 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by mqingyn on 2015/1/15.
import time
from datetime import datetime
from tornask.manager import taskmgr, run_tasks
from tornado.concurrent import run_on_executor
from tornado.netutil import ThreadedResolver, IOLoop
from tornado.httpclient import AsyncHTTPClient
from tornado.gen import coroutine
class Task(object):
def __init__(self):
self.executor = ThreadedResolver().executor
self.io_loop = IOLoop.current()
@run_on_executor
def task_interval(self):
print 'start at', datetime.now()
time.sleep(3)
print 'end at', datetime.now()
@coroutine
def task_callat(self):
response = yield AsyncHTTPClient().fetch("http://www.baidu.com")
print response.body
if __name__ == '__main__':
tasks = Task()
taskmgr.task_register("task_at", tasks.task_interval, interval=1)
taskmgr.task_register("task_callat", tasks.task_callat, call_at=("23:25", "23:35"))
run_tasks()