免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2138 | 回复: 3
打印 上一主题 下一主题

django调用函数不成功 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-05-24 16:37 |只看该作者 |倒序浏览
from birdman.include.machine import cpu_info,mem_info,disk_info,load_info
import threading,os,sys
from django.shortcuts import render_to_response
from birdman.models import Machineinfo

server_list = '/data/serverlist/host.conf'

def machine_info(ip):
        host_ip = []
        machineinfo = []
        host_ip.append(ip.strip())
        machineinfo = host_ip + cpu_info(ip) + mem_info(ip) + disk_info(ip) + load_info(ip)     #cpu、内存等信息,用列表返回
        p = Machineinfo.objects.filter(host=ip.strip())           #Machineinfo这是一个模型类
        if(p.exists()):
                p.update(logic_core=machineinfo[1])
                p.update(phy_cpu=machineinfo[2])
                p.update(core_per_phy=machineinfo[3])
                p.update(cpu_model=machineinfo[4])
                p.update(phy_mem=machineinfo[5])
                p.update(free_mem=machineinfo[6])
                p.update(max_disk=machineinfo[7])
                p.update(load=machineinfo[8])
        else:
                Machineinfo.objects.create(host=machineinfo[0],logic_core=machineinfo[1],phy_cpu=machineinfo[2],core_per_phy=machineinfo[3],cpu_model=machineinfo[4],
                                phy_mem=machineinfo[5],free_mem=machineinfo[6],max_disk=machineinfo[7],load=machineinfo[8])

        #print machineinfo
        #p.save()


def all_machine_info():
        f = open(server_list)
        lines = f.readlines()
        for ip in lines:
                a = threading.Thread(target = machine_info,args = (ip,))
                a.start()
        f.close()
#all_machine_info()
def html_machine_info(request):
        all_machine_info()
        result = Machineinfo.objects.all()
        return render_to_response('machine_info.html',{'result': result})

功能:收集各机器的信息,用多线程实现。
http://x.x.x.x/html_machine_info/访问的时候,all_machine_info()函数没有执行,不知道为什么?我手动执行是成功的。

论坛徽章:
0
2 [报告]
发表于 2013-05-27 11:12 |只看该作者
我对收集系统信息的过程比较感兴趣...


   

论坛徽章:
0
3 [报告]
发表于 2013-05-27 11:24 |只看该作者
几个建议:

1. 开启debug看看
2. 插入print看看执行过程
3. 推荐pstutil模块

论坛徽章:
0
4 [报告]
发表于 2013-05-27 14:24 |只看该作者
回复 3# easedays

debug已开,all_machine_info函数能正常执行,这里不能执行是不是跟多线程有关?

   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP