Last active
March 11, 2016 00:47
-
-
Save zhangchunlin/8520200 to your computer and use it in GitHub Desktop.
tmp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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