当遇到numpy运行多处理时,我遇到了一个问题,即Python意外退出.我已经解决了这个问题,所以我现在可以确认在运行下面描述的代码时多处理工作是完美的:
import numpy as np
from multiprocessing import Pool, Process
import time
import cPickle as p
def test(args):
x,i = args
if i == 2:
time.sleep(4)
arr = np.dot(x.T,x)
print i
if __name__ == '__main__':
x = np.random.random(size=((2000,500)))
evaluations = [(x,i) for i in range(5)]
p = Pool()
p.map_async(test,evaluations)
p.close()
p.join()
Run Code Online (Sandbox Code Playgroud)
当我尝试评估下面的代码时会出现问题.这使Python意外退出:
import numpy as np
from multiprocessing import Pool, Process
import time
import cPickle as p
def test(args):
x,i = args
if i == 2:
time.sleep(4)
arr = np.dot(x.T,x) …Run Code Online (Sandbox Code Playgroud) 我正在Google App Engine上开发一个应用程序并遇到了问题.我想为每个用户会话添加一个cookie,以便我能够区分当前用户.我希望他们都是匿名的,因此我不想登录.因此我实现了以下cookie代码.
def clear_cookie(self,name,path="/",domain=None):
"""Deletes the cookie with the given name."""
expires = datetime.datetime.utcnow() - datetime.timedelta(days=365)
self.set_cookie(name,value="",path=path,expires=expires,
domain=domain)
def clear_all_cookies(self):
"""Deletes all the cookies the user sent with this request."""
for name in self.cookies.iterkeys():
self.clear_cookie(name)
def get_cookie(self,name,default=None):
"""Gets the value of the cookie with the given name,else default."""
if name in self.request.cookies:
return self.request.cookies[name]
return default
def set_cookie(self,name,value,domain=None,expires=None,path="/",expires_days=None):
"""Sets the given cookie name/value with the given options."""
name = _utf8(name)
value = _utf8(value)
if re.search(r"[\x00-\x20]",name + value): # Don't …Run Code Online (Sandbox Code Playgroud)