Wednesday, 15 August 2012

python - update the database while using the timer -



python - update the database while using the timer -

i'm working on python script write info in sqlite3 database @ same time when using time.sleep function. i'm having problem writing database @ same time when i'm using time.sleep function.

i can able create database table without have problem, when utilize time.sleep function, stop writing info database.

when utilize code:

import time import threading #download xml source here url = addon.getsetting('allchannel.url') req = urllib2.request(url) response = urllib2.urlopen(req) info = response.read() response.close() profilepath = xbmc.translatepath(os.path.join('special://userdata/addon_data/script.tvguide','')) self.getcontrol(4202).setlabel("1%") if os.path.exists(profilepath): profilepath = profilepath + 'source.db' con = database.connect(profilepath) cur = con.cursor() cur.execute('create table programs(channel text, title text, start_date timestamp, stop_date timestamp, description text)') con.commit() con.close tv_elem = elementtree.parse(stringio.stringio(data)).getroot() profilepath = xbmc.translatepath(os.path.join('special://userdata/addon_data/script.tvguide', '')) profilepath = profilepath + 'source.db' con = sqlite3.connect(profilepath) cur = con.cursor() channels = ordereddict() # loaded info channel in tv_elem.findall('channel'): channel_name = channel.find('display-name').text programme in channel.findall('programme'): title = program.find('title').text start_time = program.get("start") stop_time = program.get("stop") cur.execute("insert programs(channel, title, start_date, stop_date)" + " values(?, ?, ?, ?)", [channel_name, title, start_time, stop_time]) con.commit() con.close time.sleep(2) #stop timer , set timer 1 time again 2 seconds self.getcontrol(4202).setlabel("8%") time.sleep(2) #stop timer , set timer 1 time again 2 seconds self.getcontrol(4202).setlabel("16%") time.sleep(2) #stop timer , set timer 1 time again 2 seconds self.getcontrol(4202).setlabel("24%")

so when seek without using time.sleep function:

# loaded info channel in tv_elem.findall('channel'): channel_name = channel.find('display-name').text programme in channel.findall('programme'): title = program.find('title').text start_time = program.get("start") stop_time = program.get("stop") cur.execute("insert programs(channel, title, start_date, stop_date)" + " values(?, ?, ?, ?)", [channel_name, title, start_time, stop_time]) con.commit() con.close

it allow me write info database if utilize without time.sleep function. want utilize time.sleep function or timer, because want update string in setlabel function in every 2 seconds while i'm writing info database. tried utilize while loop, freeze application i'm running on.

can please tell me how can write info database @ same time when i'm using time.sleep or timer function?

edit: many prints when running threading:

15:39:51 t:6980 notice: hello, world 15:39:51 t:2104 notice: hello, world 15:39:51 t:6924 notice: hello, world 15:39:51 t:6052 notice: hello, world 15:39:51 t:1696 notice: hello, world 15:39:51 t:6164 notice: hello, world 15:39:51 t:1312 notice: hello, world 15:39:51 t:3804 notice: hello, world 15:39:51 t:6364 notice: hello, world 15:39:51 t:4208 notice: hello, world 15:39:51 t:3332 notice: hello, world 15:39:51 t:5428 notice: hello, world 15:39:51 t:920 notice: hello, world 15:39:51 t:6408 notice: hello, world 15:39:51 t:7000 notice: hello, world 15:39:51 t:1988 notice: hello, world 15:39:51 t:5544 notice: hello, world 15:39:51 t:6620 notice: hello, world 15:39:51 t:6448 notice: hello, world 15:39:51 t:1536 notice: hello, world 15:39:51 t:1132 notice: hello, world 15:39:51 t:6548 notice: hello, world 15:39:51 t:1892 notice: hello, world 15:39:51 t:6532 notice: hello, world 15:39:51 t:3856 notice: hello, world 15:39:51 t:788 notice: hello, world 15:39:51 t:6416 notice: hello, world 15:39:51 t:5692 notice: hello, world 15:39:51 t:5256 notice: hello, world 15:39:51 t:6696 notice: hello, world 15:39:51 t:1352 notice: hello, world 15:39:51 t:6656 notice: hello, world 15:39:51 t:4844 notice: hello, world 15:39:51 t:4672 notice: hello, world 15:39:51 t:3636 notice: hello, world 15:39:51 t:7052 notice: hello, world 15:39:51 t:6264 notice: hello, world 15:39:51 t:6336 notice: hello, world 15:39:51 t:6332 notice: hello, world 15:39:51 t:7064 notice: hello, world 15:39:51 t:7148 notice: hello, world 15:39:51 t:6984 notice: hello, world 15:39:51 t:4924 notice: hello, world 15:39:51 t:5716 notice: hello, world 15:39:51 t:6960 notice: hello, world 15:39:51 t:1828 notice: hello, world 15:39:51 t:5492 notice: hello, world 15:39:51 t:6560 notice: hello, world 15:39:51 t:3328 notice: hello, world 15:39:51 t:6880 notice: hello, world 15:39:51 t:6152 notice: hello, world 15:39:51 t:6892 notice: hello, world 15:39:51 t:5048 notice: hello, world 15:39:51 t:6788 notice: hello, world 15:39:51 t:6168 notice: hello, world 15:39:51 t:4656 notice: hello, world 15:39:51 t:6392 notice: hello, world 15:39:51 t:6928 notice: hello, world 15:39:52 t:6240 notice: hello, world 15:39:52 t:5240 notice: hello, world 15:39:52 t:6824 notice: hello, world 15:39:52 t:6716 notice: hello, world 15:39:52 t:5384 notice: hello, world 15:39:52 t:6008 notice: hello, world 15:39:52 t:2280 notice: hello, world 15:39:52 t:2612 notice: hello, world 15:39:52 t:6012 notice: hello, world 15:39:52 t:6820 notice: hello, world 15:39:52 t:7080 notice: hello, world 15:39:52 t:2556 notice: hello, world 15:39:52 t:3904 notice: hello, world 15:39:52 t:4284 notice: hello, world 15:39:52 t:5648 notice: hello, world 15:39:52 t:6076 notice: hello, world 15:39:52 t:6516 notice: hello, world 15:39:52 t:6552 notice: hello, world 15:39:52 t:6768 notice: hello, world 15:39:52 t:3464 notice: hello, world 15:39:52 t:1240 notice: hello, world 15:39:52 t:1992 notice: hello, world 15:39:52 t:6896 notice: hello, world 15:39:52 t:6288 notice: hello, world 15:39:52 t:6212 notice: hello, world 15:39:52 t:6672 notice: hello, world 15:39:52 t:7040 notice: hello, world 15:39:52 t:6280 notice: hello, world 15:39:52 t:7112 notice: hello, world 15:39:52 t:5760 notice: hello, world 15:39:52 t:6664 notice: hello, world 15:39:52 t:6952 notice: hello, world 15:39:52 t:7024 notice: hello, world 15:39:52 t:6224 notice: hello, world 15:39:52 t:5356 notice: hello, world 15:39:52 t:5628 notice: hello, world 15:39:52 t:4220 notice: hello, world 15:39:52 t:6160 notice: hello, world 15:39:52 t:6320 notice: hello, world 15:39:52 t:4384 notice: hello, world 15:39:52 t:6572 notice: hello, world 15:39:52 t:5284 notice: hello, world 15:39:52 t:7060 notice: hello, world 15:39:52 t:3256 notice: hello, world 15:39:52 t:5008 notice: hello, world 15:39:52 t:6124 notice: hello, world 15:39:52 t:912 notice: hello, world 15:39:52 t:5408 notice: hello, world 15:39:52 t:5560 notice: hello, world 15:39:52 t:4052 notice: hello, world 15:39:52 t:4416 notice: hello, world 15:39:52 t:5392 notice: hello, world 15:39:52 t:6236 notice: hello, world 15:39:52 t:5940 notice: hello, world 15:39:52 t:540 notice: hello, world 15:39:52 t:4596 notice: hello, world 15:39:52 t:3796 notice: hello, world 15:39:52 t:6700 notice: hello, world 15:39:52 t:6772 notice: hello, world 15:39:52 t:7092 notice: hello, world 15:39:52 t:6868 notice: hello, world 15:39:53 t:5292 notice: hello, world 15:39:53 t:6440 notice: hello, world 15:39:53 t:6060 notice: hello, world 15:39:53 t:5360 notice: hello, world 15:39:53 t:5984 notice: hello, world 15:39:53 t:6900 notice: hello, world 15:39:53 t:4412 notice: hello, world 15:39:53 t:2812 notice: hello, world 15:39:53 t:5756 notice: hello, world 15:39:53 t:4048 notice: hello, world 15:39:53 t:5596 notice: hello, world 15:39:53 t:6936 notice: hello, world 15:39:53 t:6612 notice: hello, world 15:39:53 t:1768 notice: hello, world 15:39:53 t:5496 notice: hello, world 15:39:53 t:3168 notice: hello, world 15:39:53 t:4444 notice: hello, world 15:39:53 t:7036 notice: hello, world 15:39:53 t:2896 notice: hello, world 15:39:53 t:7164 notice: hello, world 15:39:53 t:6032 notice: hello, world 15:39:53 t:6912 notice: hello, world 15:39:53 t:4448 notice: hello, world 15:39:53 t:3132 notice: hello, world 15:39:53 t:6708 notice: hello, world 15:39:53 t:6556 notice: hello, world 15:39:53 t:6184 notice: hello, world 15:39:53 t:6588 notice: hello, world 15:39:53 t:5700 notice: hello, world 15:39:53 t:6404 notice: hello, world 15:39:53 t:6244 notice: hello, world 15:39:53 t:3528 notice: hello, world 15:39:53 t:7132 notice: hello, world 15:39:53 t:6808 notice: hello, world 15:39:53 t:6004 notice: hello, world 15:39:53 t:876 notice: hello, world 15:39:53 t:5080 notice: hello, world 15:39:53 t:6668 notice: hello, world 15:39:53 t:5580 notice: hello, world 15:39:53 t:5488 notice: hello, world 15:39:53 t:6344 notice: hello, world 15:39:53 t:5732 notice: hello, world 15:39:53 t:4160 notice: hello, world 15:39:53 t:6300 notice: hello, world 15:39:53 t:3472 notice: hello, world 15:39:53 t:2772 notice: hello, world 15:39:53 t:3444 notice: hello, world 15:39:53 t:6568 notice: hello, world 15:39:53 t:6856 notice: hello, world 15:39:53 t:984 notice: hello, world 15:39:53 t:6748 notice: hello, world 15:39:53 t:6920 notice: hello, world 15:39:53 t:5712 notice: hello, world 15:39:53 t:6248 notice: hello, world 15:39:53 t:5532 notice: hello, world 15:39:53 t:5344 notice: hello, world 15:39:53 t:1484 notice: hello, world 15:39:53 t:5804 notice: hello, world 15:39:53 t:3632 notice: hello, world 15:39:53 t:6780 notice: hello, world 15:39:53 t:4760 notice: hello, world 15:39:53 t:6888 notice: hello, world 15:39:53 t:7156 notice: hello, world 15:39:54 t:6932 notice: hello, world 15:39:54 t:7144 notice: hello, world 15:39:54 t:6980 notice: hello, world 15:39:54 t:4128 notice: hello, world 15:39:54 t:6956 notice: hello, world 15:39:54 t:6924 notice: hello, world 15:39:54 t:6376 notice: hello, world 15:39:54 t:5820 notice: hello, world 15:39:54 t:6052 notice: hello, world 15:39:54 t:1696 notice: hello, world 15:39:54 t:1312 notice: hello, world 15:39:54 t:3804 notice: hello, world 15:39:54 t:4208 notice: hello, world 15:39:54 t:5428 notice: hello, world 15:39:54 t:6408 notice: hello, world 15:39:54 t:6728 notice: hello, world 15:39:54 t:5544 notice: hello, world 15:39:54 t:6448 notice: hello, world 15:39:54 t:1132 notice: hello, world 15:39:54 t:1892 notice: hello, world 15:39:54 t:3856 notice: hello, world 15:39:54 t:6416 notice: hello, world 15:39:54 t:5256 notice: hello, world 15:39:54 t:5536 notice: hello, world 15:39:54 t:2860 notice: hello, world 15:39:54 t:4844 notice: hello, world 15:39:54 t:4268 notice: hello, world 15:39:54 t:3636 notice: hello, world 15:39:54 t:7052 notice: hello, world 15:39:54 t:6264 notice: hello, world 15:39:54 t:6508 notice: hello, world 15:39:54 t:2728 notice: hello, world 15:39:54 t:3608 notice: hello, world 15:39:54 t:5764 notice: hello, world 15:39:54 t:7064 notice: hello, world 15:39:54 t:7148 notice: hello, world 15:39:54 t:3616 notice: hello, world 15:39:54 t:5716 notice: hello, world 15:39:54 t:416 notice: hello, world 15:39:54 t:6216 notice: hello, world 15:39:54 t:1828 notice: hello, world 15:39:54 t:5492 notice: hello, world 15:39:54 t:6560 notice: hello, world 15:39:54 t:4392 notice: hello, world 15:39:54 t:7096 notice: hello, world 15:39:54 t:6436 notice: hello, world 15:39:54 t:5048 notice: hello, world 15:39:54 t:6788 notice: hello, world 15:39:54 t:3300 notice: hello, world 15:39:54 t:6392 notice: hello, world 15:39:54 t:5608 notice: hello, world 15:39:54 t:6240 notice: hello, world 15:39:54 t:4976 notice: hello, world 15:39:54 t:5752 notice: hello, world 15:39:54 t:2944 notice: hello, world 15:39:54 t:4640 notice: hello, world 15:39:54 t:2268 notice: hello, world 15:39:54 t:6716 notice: hello, world 15:39:54 t:2148 notice: hello, world 15:39:54 t:5500 notice: hello, world 15:39:54 t:5416 notice: hello, world 15:39:54 t:5384 notice: hello, world 15:39:54 t:5512 notice: hello, world 15:39:54 t:5844 notice: hello, world 15:39:54 t:2280 notice: hello, world 15:39:54 t:2612 notice: hello, world 15:39:54 t:6012 notice: hello, world 15:39:54 t:6820 notice: hello, world 15:39:54 t:3904 notice: hello, world 15:39:54 t:5648 notice: hello, world 15:39:54 t:6516 notice: hello, world 15:39:54 t:6768 notice: hello, world 15:39:54 t:3464 notice: hello, world 15:39:54 t:6896 notice: hello, world 15:39:54 t:7040 notice: hello, world 15:39:54 t:6672 notice: hello, world 15:39:54 t:5760 notice: hello, world 15:39:54 t:6664 notice: hello, world 15:39:54 t:7024 notice: hello, world 15:39:54 t:5956 notice: hello, world 15:39:54 t:6632 notice: hello, world 15:39:54 t:5452 notice: hello, world 15:39:54 t:5356 notice: hello, world 15:39:54 t:6704 notice: hello, world 15:39:54 t:6352 notice: hello, world 15:39:54 t:6660 notice: hello, world 15:39:54 t:1436 notice: hello, world 15:39:54 t:6252 notice: hello, world 15:39:54 t:6348 notice: hello, world 15:39:54 t:6832 notice: hello, world 15:39:54 t:5628 notice: hello, world 15:39:54 t:4220 notice: hello, world 15:39:54 t:6160 notice: hello, world 15:39:55 t:7004 notice: hello, world 15:39:55 t:6740 notice: hello, world 15:39:55 t:6572 notice: hello, world 15:39:55 t:6592 notice: hello, world 15:39:55 t:7116 notice: hello, world 15:39:55 t:6504 notice: hello, world 15:39:55 t:5008 notice: hello, world 15:39:55 t:6636 notice: hello, world 15:39:55 t:1172 notice: hello, world 15:39:55 t:4156 notice: hello, world 15:39:55 t:5560 notice: hello, world 15:39:55 t:6188 notice: hello, world 15:39:55 t:6120 notice: hello, world 15:39:55 t:6576 notice: hello, world 15:39:55 t:6324 notice: hello, world 15:39:55 t:6712 notice: hello, world 15:39:55 t:5940 notice: hello, world 15:39:55 t:6064 notice: hello, world 15:39:55 t:7008 notice: hello, world 15:39:55 t:4596 notice: hello, world 15:39:55 t:6700 notice: hello, world 15:39:55 t:7092 notice: hello, world 15:39:55 t:5292 notice: hello, world 15:39:55 t:6060 notice: hello, world 15:39:55 t:5360 notice: hello, world 15:39:55 t:4412 notice: hello, world 15:39:55 t:2812 notice: hello, world 15:39:55 t:6724 notice: hello, world 15:39:55 t:4048 notice: hello, world 15:39:55 t:2104 notice: hello, world 15:39:55 t:5596 notice: hello, world 15:39:55 t:5196 notice: hello, world 15:39:55 t:2892 notice: hello, world 15:39:55 t:4484 notice: hello, world 15:39:55 t:6164 notice: hello, world 15:39:55 t:6608 notice: hello, world 15:39:55 t:6364 notice: hello, world 15:39:55 t:4444 notice: hello, world 15:39:55 t:7036 notice: hello, world 15:39:55 t:2896 notice: hello, world 15:39:55 t:6620 notice: hello, world 15:39:55 t:6548 notice: hello, world 15:39:55 t:788 notice: hello, world 15:39:55 t:6696 notice: hello, world 15:39:55 t:6656 notice: hello, world 15:39:55 t:4672 notice: hello, world 15:39:55 t:5224 notice: hello, world 15:39:55 t:1500 notice: hello, world 15:39:55 t:6332 notice: hello, world 15:39:55 t:5260 notice: hello, world 15:39:55 t:4924 notice: hello, world 15:39:55 t:6964 notice: hello, world 15:39:55 t:6960 notice: hello, world 15:39:55 t:6880 notice: hello, world 15:39:55 t:6304 notice: hello, world 15:39:55 t:6168 notice: hello, world 15:39:55 t:6928 notice: hello, world 15:39:55 t:6600 notice: hello, world 15:39:55 t:5240 notice: hello, world 15:39:55 t:7164 notice: hello, world 15:39:55 t:6872 notice: hello, world 15:39:55 t:6824 notice: hello, world 15:39:55 t:4616 notice: hello, world 15:39:55 t:6708 notice: hello, world 15:39:55 t:6556 notice: hello, world 15:39:55 t:3224 notice: hello, world 15:39:55 t:1032 notice: hello, world 15:39:55 t:1492 notice: hello, world 15:39:55 t:6008 notice: hello, world 15:39:55 t:6904 notice: hello, world 15:39:55 t:3440 notice: hello, world 15:39:55 t:3528 notice: hello, world 15:39:55 t:6004 notice: hello, world 15:39:55 t:6232 notice: hello, world 15:39:55 t:6808 notice: hello, world 15:39:55 t:6668 notice: hello, world 15:39:55 t:5732 notice: hello, world 15:39:55 t:4160 notice: hello, world 15:39:55 t:6300 notice: hello, world 15:39:55 t:2772 notice: hello, world 15:39:55 t:3444 notice: hello, world 15:39:55 t:6568 notice: hello, world 15:39:55 t:1240 notice: hello, world 15:39:55 t:1992 notice: hello, world 15:39:55 t:6212 notice: hello, world 15:39:55 t:6920 notice: hello, world 15:39:55 t:6248 notice: hello, world 15:39:55 t:6280 notice: hello, world 15:39:55 t:7112 notice: hello, world 15:39:55 t:6952 notice: hello, world 15:39:55 t:6224 notice: hello, world 15:39:55 t:4172 notice: hello, world 15:39:56 t:6780 notice: hello, world 15:39:56 t:4760 notice: hello, world 15:39:56 t:6888 notice: hello, world 15:39:56 t:6308 notice: hello, world 15:39:56 t:6752 notice: hello, world 15:39:56 t:6764 notice: hello, world 15:39:56 t:1856 notice: hello, world 15:39:56 t:5464 notice: hello, world 15:39:56 t:6784 notice: hello, world 15:39:56 t:4384 notice: hello, world 15:39:56 t:5232 notice: hello, world 15:39:56 t:4128 notice: hello, world 15:39:56 t:5284 notice: hello, world 15:39:56 t:6376 notice: hello, world 15:39:56 t:3256 notice: hello, world 15:39:56 t:1312 notice: hello, world 15:39:56 t:3804 notice: hello, world 15:39:56 t:6408 notice: hello, world 15:39:56 t:5392 notice: hello, world 15:39:56 t:1132 notice: hello, world

i'm not familiar with way take progressbar, basicly sleep app sounds bad thought me, , might want find improve way it.

but, if want run 2 different actions - need utilize threading. little example

def function_1(): in range(5): print "1111" time.sleep(1) def function_2(): in range(5): print "2222" time.sleep(1) t1 = threading.thread(target=function_1) t2 = threading.thread(target=function_2) t1.start() t2.start()

if called 2 functions without threading , out of '111's , '222's.

when using threading got this:

1111 2222 2222 1111 1111 2222 2222 1111 2222 1111

because happened paralleled. hope clear enough.

python python-2.7 xbmc

No comments:

Post a Comment