Ejemplo n.º 1
0
 def _init_shadow_hist(self):
     try:
         self.shadow_db = PickleShareDB(os.path.join(
                                        self.shell.ipython_dir, 'db'))
     except UnicodeDecodeError:
         print("Your ipython_dir can't be decoded to unicode!")
         print("Please set HOME environment variable to something that")
         print(r"only has ASCII characters, e.g. c:\home")
         print("Now it is", self.ipython_dir)
         sys.exit()
     self.shadow_hist = ShadowHist(self.shadow_db, self.shell)
Ejemplo n.º 2
0
    def test_stress(self):
        db = PickleShareDB('~/fsdbtest')
        import time, sys
        for i in range(1000):
            for j in range(1000):
                if i % 15 == 0 and i < 200:
                    if str(j) in db:
                        del db[str(j)]
                    continue

                if j % 33 == 0:
                    time.sleep(0.02)

                db[str(j)] = db.get(str(j),
                                    []) + [(i, j, "proc %d" % os.getpid())]
                db.hset('hash', j, db.hget('hash', j, 15) + 1)

            print(i, end=' ')
            sys.stdout.flush()
            if i % 10 == 0:
                db.uncache()
Ejemplo n.º 3
0
    def test_stress(self):
        db = PickleShareDB("~/fsdbtest")
        import time, sys

        for i in range(1000):
            for j in range(1000):
                if i % 15 == 0 and i < 200:
                    if str(j) in db:
                        del db[str(j)]
                    continue

                if j % 33 == 0:
                    time.sleep(0.02)

                db[str(j)] = db.get(str(j), []) + [(i, j, "proc %d" % os.getpid())]
                db.hset("hash", j, db.hget("hash", j, 15) + 1)

            print(i, end=" ")
            sys.stdout.flush()
            if i % 10 == 0:
                db.uncache()
Ejemplo n.º 4
0
    def test_picklesharedb(self):
        db = PickleShareDB(self.tempdir.name)
        db.clear()
        print("Should be empty:", db.items())
        db['hello'] = 15
        db['aku ankka'] = [1, 2, 313]
        db['paths/nest/ok/keyname'] = [1, (5, 46)]
        db.hset('hash', 'aku', 12)
        db.hset('hash', 'ankka', 313)
        self.assertEqual(db.hget('hash', 'aku'), 12)
        self.assertEqual(db.hget('hash', 'ankka'), 313)
        print("all hashed", db.hdict('hash'))
        print(db.keys())
        print(db.keys('paths/nest/ok/k*'))
        print(dict(db))  # snapsot of whole db
        db.uncache()  # frees memory, causes re-reads later

        # shorthand for accessing deeply nested files
        lnk = db.getlink('myobjects/test')
        lnk.foo = 2
        lnk.bar = lnk.foo + 5
        self.assertEqual(lnk.bar, 7)
Ejemplo n.º 5
0
    def test_picklesharedb(self):
        db = PickleShareDB(self.tempdir.name)
        db.clear()
        print("Should be empty:", db.items())
        db["hello"] = 15
        db["aku ankka"] = [1, 2, 313]
        db["paths/nest/ok/keyname"] = [1, (5, 46)]
        db.hset("hash", "aku", 12)
        db.hset("hash", "ankka", 313)
        self.assertEqual(db.hget("hash", "aku"), 12)
        self.assertEqual(db.hget("hash", "ankka"), 313)
        print("all hashed", db.hdict("hash"))
        print(db.keys())
        print(db.keys("paths/nest/ok/k*"))
        print(dict(db))  # snapsot of whole db
        db.uncache()  # frees memory, causes re-reads later

        # shorthand for accessing deeply nested files
        lnk = db.getlink("myobjects/test")
        lnk.foo = 2
        lnk.bar = lnk.foo + 5
        self.assertEqual(lnk.bar, 7)