import redis
from multiprocessing import Pool
import random
import time
def redisInput(redisOb):
time.sleep(2)
print 'test process start'
print redisOb
if __name__ == '__main__':
print 'Input...'
redisOb = redis.Redis(host='10.237.36.108', port=3333, db=0)
p = Pool(5)
for x in range (5):
args = (redisOb,)
#args = (1,)
print type(args)
p.apply_async(redisInput,args)
p.close()
p.join()
print 'The end'
问题出在 p.apply_async 传递的参数上,如果把 args = (redisOb,),改成 args = (1,);子进程就正常了
求各位达人能帮忙看一下。
1
fds 2016-09-28 19:48:35 +08:00
……不能传这个吧。你可以把 redis 的参数传进去,每个进程自己创建连接。
|
2
kfll 2016-09-28 20:17:13 +08:00 2
|
5
BiggerLonger 2016-09-28 22:22:29 +08:00 via Android
pickle
|