最近调整原来的py爬虫时发现一个问题
在多线程下pymongo会报一个危险
/usr/lib64/python2.6/site-packages/pymongo/topology.py:75:
UserWarning: MongoClient opened before fork. Create MongoClient with connect=False,
or create client after forking. See PyMongo's documentation for details:
http://api.mongodb.org/python/current/faq.html#using-pymongo-with-multiprocessing>
"MongoClient opened before fork. Create MongoClient "
大意是多进程下要加上connect=False参数防止死锁?
然后加上这个参数程序依旧报这个危险,所以问下多进程下 pymongo的要在哪里初始化?
目前是这样
class mongo():
def __init__(self):
try:
client = MongoClient(host="127.0.0.1", port=27017, connect=False)
db = client.db
print "mogodb successful connection~^_^"
except Exception, e:
print "mogodb Error", e
def in():
......
拜谢