I ran into a problem with a closed database file which can't be copied after closing it. Below is a quite extensive code snippet to demonstrate the problem. The original code is much more complex, but this was the smallest example I could reproduce the error with.
A database is created/opened and data written to it. In the function exit_key_handler the database is closed and a backup file should be copied to another directory. Here the problem occurs:
The shutil.copyfile command failes with this error message.
When the two code lines commented out in function new() are activated and the equivalent lines are commented out in function run, everything works like expected. Anyone knows why?Code:File "c:\resource\shutil.py", line 17, in copyfile fsrc = open(src, 'rb') IOError: [Errno 13] Permission denied: 'C:\\Test.dat'
Code:import appuifw import os import shutil import e32 import e32db def new(): integer = 100 string = u"" # dbv_dat = e32db.Db_view() # dbv_dat.prepare(db_dat, u"SELECT * FROM test") db_dat.begin() sql_add = u"INSERT INTO test (test_1,test_2) VALUES (%d,'%s')"%(integer,string) db_dat.execute(sql_add) db_dat.commit() def exit_key_handler(): db_dat.compact() db_dat.close() data_backup_path = u"C:\\Backup" if not os.path.exists(data_backup_path): os.makedirs(data_backup_path) shutil.copyfile(u"C:\\Test.dat",u"C:\\Backup\\Test.dat") app_lock.signal() def run(): global db_dat global app_lock global dbv_dat db_file = u"C:\\Test.dat" db_dat = e32db.Dbms() try: db_dat.open(db_file) except: db_dat.create(db_file) db_dat.open(db_file) db_dat.begin() sql_create = u"CREATE TABLE test (test_1 INTEGER, test_2 VARCHAR)" db_dat.execute(sql_create) db_dat.commit() dbv_dat = e32db.Db_view() dbv_dat.prepare(db_dat, u"SELECT * FROM test") new() appuifw.app.screen = 'normal' app_lock = e32.Ao_lock() appuifw.app.exit_key_handler = exit_key_handler app_lock.wait() run()

Reply With Quote

