django celery执行异步任务问题
taskWork.py内容
from GameOps import celery_app
import time
@celery_app.task
def addServerTask():
for i in range(5):
print i
print 'dddddddddd'
print 'wwwwwwwwwwwwww'
time.sleep(6)
viewes.py内容
from taskWork import addServerTask
def addServerViews(request):
addServerTask.delay()
print 'sssssss'
return HttpResponse('23333~~~')
url.py内容
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$',views.addServerViews,name='index')
]
所以当访问首页时候,task中的print没有在终端显示的
Django version 1.10.5, using settings 'GameOps.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
sssssss
[28/Feb/2017 10:43:11] "GET / HTTP/1.1" 200 8
sssssss
[28/Feb/2017 10:46:35] "GET / HTTP/1.1" 200 8
celery执行的日志
[2017-02-28 10:43:17,879: WARNING/PoolWorker-10] 1
[2017-02-28 10:43:23,886: WARNING/PoolWorker-10] 2
[2017-02-28 10:43:29,892: WARNING/PoolWorker-10] 3
[2017-02-28 10:43:35,899: WARNING/PoolWorker-10] 4
[2017-02-28 10:43:41,913: INFO/PoolWorker-10] Task eva.taskWork.addServerTask[cbf69d7e-109b-4548-a66b-dea282ceba1e] succeeded in 30.04137092s: None
[2017-02-28 10:46:35,916: INFO/MainProcess] Received task: eva.taskWork.addServerTask[3bb831e8-a6ab-44a7-81f5-52ffaf4b1381]
[2017-02-28 10:46:35,918: WARNING/PoolWorker-1] 0
[2017-02-28 10:46:41,922: WARNING/PoolWorker-1] 1
[2017-02-28 10:46:47,929: WARNING/PoolWorker-1] 2
[2017-02-28 10:46:53,932: WARNING/PoolWorker-1] 3
[2017-02-28 10:46:59,938: WARNING/PoolWorker-1] 4
[2017-02-28 10:47:05,946: INFO/PoolWorker-1] Task eva.taskWork.addServerTask[3bb831e8-a6ab-44a7-81f5-52ffaf4b1381] succeeded in 30.028110039s: None
那异步执行任务的print去哪里了?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试用 logging 模块