masscreate2.py

来自「SQLAlchemy. 经典的Python ORM框架。学习必看。」· Python 代码 · 共 37 行

PY
37
字号
import testenv; testenv.simple_setup()import gcimport random, stringfrom sqlalchemy.orm import attributes# with this test, run top.  make sure the Python process doenst grow in size arbitrarily.class User(object):    passclass Address(object):    passattributes.register_attribute(User, 'id', False, False)attributes.register_attribute(User, 'name', False, False)attributes.register_attribute(User, 'addresses', True, False)attributes.register_attribute(Address, 'email', False, False)attributes.register_attribute(Address, 'user', False, False)for i in xrange(1000):  for j in xrange(1000):    u = User()    attributes.manage(u)    u.name = str(random.randint(0, 100000000))    for k in xrange(10):      a = Address()      a.email_address = str(random.randint(0, 100000000))      attributes.manage(a)      u.addresses.append(a)      a.user = u  print "clearing"  #managed_attributes.clear()  gc.collect()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?