yum install python-setuptools
easy_install pip
pip install tornado
yum install MySQL-python

test.py里面的内容

#coding:utf-
import tornado.web
import tornado.options
import tornado.ioloop from tornado.options import define,options
define('port',default=,help='run on the given port',type=int) class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write('hello world') application = tornado.web.Application([(r'/',MainHandler),],debug=True) if __name__=='__main__':
tornado.options.parse_command_line()
application.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
#coding:utf-
import tornado.web
import tornado.options
import tornado.ioloop from tornado.options import define,options
define('port',default=,help='run on the given port',type=int) mport tornado.web
import tornado.options
import tornado.ioloop from tornado.options import define,options
define('port',default=,help='run on the given port',type=int) class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write('hello world') application = tornado.web.Application([(r'/',MainHandler),],debug=True) if __name__=='__main__':
tornado.options.parse_command_line()
application.listen(options.port)
tornado.ioloop.IOLoop.instance().start()class MainHandler(tornado.web.RequestHandler):
def get(self):
[root@iZ25vn32h9hZ mnt]# vi pythonSql.py
#coding:utf-
import tornado.web
import tornado.ioloop
import tornado.options
import MySQLdb from datetime import datetime,timedelta
from tornado.options import define,options
define('port',default=,help='run on given port',type=int) def readTxt():
global cpu,memory,disk,cache
f1 = open('../wuxi147_cpu.txt','r+')
f2 = open('../wuxi147_memory.txt','r+')
f3 = open('../wuxi147_disk.txt','r+')
f4 = open('../wuxi147_cache.txt','r+')
try:
cpu = int(float(cpu)*)
memory = '%.2f'%float(x[])
memory = int(float(memory)*)
print memory
x = f3.read().splitlines()
disk = '%.2f'%float(x[])
disk = int(float(disk)*)
print disk
x = f4.read().splitlines()
cache = '%.2f'%float(x[])
cache = int(float(cache)*)
print cache
finally:
f1.close()
f2.close()
f3.close()
f4.close() def saveInSql():
global cpu,memory,disk,cache
conn = MySQLdb.connect(host='localhost',port=,user='root',passwd='niot',db='test')
cur = conn.cursor()
#cur.execute('create table performance(id int not null auto_increment primary key,cpuUsage int,memoryUsage i
nt,physicalUsage int,coreUsage int)') cur.execute("insert into performance(cpuUsage,memoryUsage,diskUsage,cacheUsage) values('%d','%d','%d','%d')"
%(cpu,memory,disk,cache)) cur.close()
conn.commit()
conn.close() class MainHandler(tornado.web.RequestHandler):
global cpu,memory,disk,cache
def get(self):
readTxt()
saveInSql()
self.render('example.html',title='Tornado get&post',x1=cpu,x2=memory,x3=disk,x4=cache) if __name__=='__main__':
tornado.options.parse_command_line()
application = tornado.web.Application([(r'/',MainHandler),],debug=True)
application.listen(options.port)
tornado.ioloop.IOLoop.instance().start()

python 第一个web程序的更多相关文章

  1. python第一个web程序

    例一: import web urls= ('/(.*)','index') app= web.application(urls,globals()) class index: def GET(sel ...

  2. 使用MyEclipse开发第一个Web程序

    MyEclipse环境配置 首先,安装一个MyEclipse,然后进行一些相关的环境配置(Window->Preferences): 比如字体.Formatter等. 也可以从Eclipse中导 ...

  3. 【LINUX】——linux如何使用Python创建一个web服务

    问:linux如何使用Python创建一个web服务? 答:一句话,Python! 一句代码: /usr/local/bin/python -m SimpleHTTPServer 8686 > ...

  4. Servlet+JSP教程之:第一个Web程序

    我们知道当浏览器发送请求给服务器后,服务器会调用并执行对应的逻辑代码进行请求处理.逻辑代 码是由程序员自己编写然后放进服务器进行运行,其实就是Servlet程序. 第一个Web程序: 开发工具: My ...

  5. Servlet+JSP(三):第一个Web程序

    Servlet+JSP(三):第一个Web程序在学习了服务器并成功安装后,我们知道当浏览器发送请求给服务器后,服务器会调用并执行对应的逻辑代码进行请求处理.逻辑代 码是由程序员自己编写然后放进服务器进 ...

  6. Django的第一个web程序及深入学习

    本学习历程参照Practical Django Projects和http://djangobook.py3k.cn上翻译的内容进行 注:本例以本机加以说明: 根据Django的安装过程可知:在命令行 ...

  7. [Ruby on Rails系列]3、初试Rails:使用Rails开发第一个Web程序

    本系列前两部分已经介绍了如何配置Ruby on Rails开发环境,现在终于进入正题啦! Part1.开发前的准备 本次的主要任务是开发第一个Rails程序.需要特别指出的是,本次我选用了一个(Paa ...

  8. 第一个web程序(web.xml , ServletConfig , ServletContext)

    一:第一个jsp程序 1.项目设计结构 2.新建Person.java package com.java.demo; public class Person { public void printSt ...

  9. Python开发一个WEB聊天室

    项目实战:开发一个WEB聊天室 功能需求: 用户可以与好友一对一聊天 可以搜索.添加某人为好友 用户可以搜索和添加群 每个群有管理员可以审批用户的加群请求,群管理员可以用多个,群管理员可以删除.添加. ...

随机推荐

  1. [bzoj1001][BJOI2006]狼抓兔子——最大流转最短路,平面图

    题目描述: 给定一个平面图,求最小割. 题解: 本题是一道经典题. 周冬Orz的论文是很好的研究资料. 这道题点太多,所以直接跑dinic无疑会超时. 我们观察原图,发现原图是一个平面图. 什么是平面 ...

  2. kvm虚拟机最佳实践系列1-kvm宿主机准备

    KVM宿主机配置 系统环境:ubuntu16, bond0 业务网口 bond1 管理网口+存储网口 安装KVM环境支持 sudo apt-get install qemu-kvm sudo apt- ...

  3. HTML5初学笔记

    今天学习了下HTML5的基本知识,用画笔在画布上画了几个东西,效果如图,相关代码如下,注意点总结在末尾: <!DOCTYPE html> <html> <head> ...

  4. Centos7下zabbix部署(四)定义报警媒介-邮件

    1.安装发送邮件工具mailx [root@zabbix-server ~]# yum install mailx -y 2.自定义使用163邮箱为默认发件人(避免被当作垃圾邮件) set from= ...

  5. [BZOJ4756][Usaco2017 Jan]Promotion Counting 树状数组

    4756: [Usaco2017 Jan]Promotion Counting Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 305  Solved: ...

  6. AC日记——The Child and Sequence codeforces 250D

    D - The Child and Sequence 思路: 因为有区间取模操作所以没法用标记下传: 我们发现,当一个数小于要取模的值时就可以放弃: 凭借这个来减少更新线段树的次数: 来,上代码: # ...

  7. csu1811(树上启发式合并)

    csu1811 题意 给定一棵树,每个节点有颜色,每次仅删掉第 \(i\) 条边 \((a_i, b_i)\) ,得到两颗树,问两颗树节点的颜色集合的交集. 分析 转化一下,即所求答案为每次删掉 \( ...

  8. hdu 1556 Color the ball 线段树

    题目链接:HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气 ...

  9. 四. Java继承和多态3. 继承中的方法的覆盖和重载

    在类继承中,子类可以修改从父类继承来的方法,也就是说子类能创建一个与父类方法有不同功能的方法,但具有相同的名称.返回值类型.参数列表. 如果在新类中定义一个方法,其名称.返回值类型和参数列表正好与父类 ...

  10. JavaEE目录

    第一章: Spring介绍 Spring项目搭建 Spring概念 第二章: Sprin配置详解 属性注入(构造方法注入,设值注入) 实例化(构造器(空参构造器),静态工厂,工厂方法) 装配(xml方 ...