Python
3
Вклад в тег
#python -m SimpleHTTPServer 8000
Serving HTTP on 0.0.0.0 port 8000 ...
Mac OS X (10.4) - Finding the IP address and MAC a...Pickle is slow
Pickle is both slower and produces larger serialized values than most of the alternatives.
To illustrate this, I put together a simple benchmark comparing pickle to the built in JSON module, the Apache Thrift library, and MessagePack. This benchmark measures the number of objects a second each of these libraries can read and write. The data being serialized here are just randomly generated fake 'Tweet' objects containing just four fields:
Pickle is the clear underperformer here. Even the 'cPickle' extension thats written in C has a serialization rate thats about a quarter that of JSON or Thrift. Pickle also produces serialized values that are around double the size of Thrift or MessagePack.
Warning: The pickle module is not intended to be secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source.
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
from os import curdir, sep
PORT_NUMBER = 8080
#This class will handles any incoming request from
#the browser
class myHandler(BaseHTTPRequestHandler):
#Handler for the GET requests
def do_GET(self):
if self.path=="/":
self.path="/index_example2.html"
try:
#Check the file extension required and
#set the right mime type
sendReply = False
if self.path.endswith(".html"):
mimetype='text/html'
sendReply = True
if self.path.endswith(".jpg"):
mimetype='image/jpg'
sendReply = True
if self.path.endswith(".gif"):
mimetype='image/gif'
sendReply = True
if self.path.endswith(".js"):
mimetype='application/javascript'
sendReply = True
if self.path.endswith(".css"):
mimetype='text/css'
sendReply = True
if sendReply == True:
#Open the static file requested and send it
f = open(curdir + sep + self.path)
self.send_response(200)
self.send_header('Content-type',mimetype)
self.end_headers()
self.wfile.write(f.read())
f.close()
return
except IOError:
self.send_error(404,'File Not Found: %s' % self.path)
try:
#Create a web server and define the handler to manage the
#incoming request
server = HTTPServer(('', PORT_NUMBER), myHandler)
print 'Started httpserver on port ' , PORT_NUMBER
#Wait forever for incoming htto requests
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down the web server'
server.socket.close()
import threading
class Repository:
def __init__(self):
self.__lock=threading.Lock()
def add(self):
with self.__lock:
with open(self.config_path,"r") as json_data:
try:
data = json.load(json_data)
except:
logging.critical( "FATAL!!!can't read %s" % data)
raise ValueError("can't json.load(%s)" % data)
import MySQLdb
#Start a connection
db= MySQLdb.connect(host="dbhost", user="dbuser" , passwd="dbpass", db="dbname")
db.autocommit(False)
cursor = db.cursor()
try:
cursor.execute("Your SQL")
cursor.execute("Another sql")
db.commit()
except:
db.rollback()
# it's example how run
[uwsgi]
plugins = python27
http-socket = :80
#pythonpath = /srv/myapp
#virtualenv = /home/project/ve
chdir = /home/project
processes = 1
threads = 4
#pythonpath = ..
module = manager:app
# This line below was important
#wsgi-file = manager.py
#callable = app
# Turn this off for production
catch-exceptions = true
stats = /.tmp/.uwsgi-stats.socket
touch-reload = /.tmp/.uwsgi-reload
Hugo is a general-purpose website framework. Technically speaking, Hugo is a static site generator. This means that, unlike systems like WordPress, Ghost and Drupal, which run on your web server expensively building a page every time a visitor requests one, Hugo does the building when you create your content. Since websites are viewed far more often than they are edited, Hugo is optimized for website viewing while providing a great writing experience.Hugo - документация.