Skip to content

Instantly share code, notes, and snippets.

@zhangchunlin
Last active March 11, 2016 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangchunlin/8520200 to your computer and use it in GitHub Desktop.
Save zhangchunlin/8520200 to your computer and use it in GitHub Desktop.
tmp
from gevent.pywsgi import WSGIServer
def application(environ, start_response):
status = '200 OK'
headers = [
('Content-Type', 'text/html')
]
start_response(status, headers)
yield "<p>Hello"
yield "World</p>"
WSGIServer(('', 8000), application).serve_forever()
g_Dict = {'a':1}
def init():
g_Dict['b'] = 2
def ProcOne(*args):
global g_Dict
print "ProcOne %s, g_Dict:%s"%(args,g_Dict)
def test8():
from multiprocessing import Pool
def ProcAll():
pool = Pool(processes=4)
for i in range(1,5):
pool.apply(ProcOne,(i,))
pool.close()
pool.join()
init()
print "after init,g_Dict:%s"%(g_Dict)
ProcAll()
if __name__ == '__main__':
test8()
def test19():
src_fpath = "gbk.txt"
dst_fpath = "utf8.txt"
dstf = open(dst_fpath,"w")
for line in open(src_fpath):
try:
dstf.write(line.decode("gbk").encode("utf8"))
except Exception as e:
print "error when handle '%s': '%s'"%(repr(line),e)
if __name__ == '__main__':
test19()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment