Python on WinXP Embedded
Has anyone install Python on Windows XP Embedded? We wish to evaluate the possible solution of installing Python with WinXPE on a PC/104 plus module. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python on WinXP Embedded
Hello rtilley, thanks for replying so soon. I wish to install WinXP Embedded on a PC/104 module and install Python on WinXP Embedded, not WinPE... The hardware which is to be acquired is about a celeron 400MHz but we just not sure how well Python will work under WinXPE... -- http://mail.python.org/mailman/listinfo/python-list
Fastest way to convert a byte of integer into a list
Hello, I'm trying to find a way to convert an integer (8-bits long for starters) and converting them to a list, e.g.: num = 255 numList = [1,1,1,1,1,1,1,1] with the first element of the list being the least significant, so that i can keep appending to that list without having to worry about the size of the integer. I need to do this because some of the function call can return a 2 lots of 32-bit numbers. I have to find a way to transport this in a list... or is there a better way? -- http://mail.python.org/mailman/listinfo/python-list
Re: Fastest way to convert a byte of integer into a list
On Jul 13, 9:54 am, Matimus <[EMAIL PROTECTED]> wrote: > On Jul 12, 3:34 pm, Godzilla <[EMAIL PROTECTED]> wrote: > > > Hello, > > > I'm trying to find a way to convert an integer (8-bits long for > > starters) and converting them to a list, e.g.: > > > num = 255 > > numList = [1,1,1,1,1,1,1,1] > > > with the first element of the list being the least significant, so > > that i can keep appending to that list without having to worry about > > the size of the integer. I need to do this because some of the > > function call can return a 2 lots of 32-bit numbers. I have to find a > > way to transport this in a list... or is there a better way? > > num = 255 > numlist = [num >> i & 1 for i in range(8)] Thanks matimus! I will look into it... -- http://mail.python.org/mailman/listinfo/python-list
Re: Fastest way to convert a byte of integer into a list
On Jul 13, 11:13 am, bsneddon <[EMAIL PROTECTED]> wrote: > On Jul 12, 8:49 pm, John Machin <[EMAIL PROTECTED]> wrote: > > > On Jul 13, 10:28 am, Paul Rubin <http://[EMAIL PROTECTED]> wrote: > > > > Godzilla <[EMAIL PROTECTED]> writes: > > > > > num = 255 > > > > > numlist = [num >> i & 1 for i in range(8)] > > > > > Thanks matimus! I will look into it... > > > > numlist = lookup_table[num] > > > > where lookup_table is a precomputed list of lists. > > > Ummm ... didn't the OP say he had 32-bit numbers??? > > List comprehension would be faster, lookup would be even faster but > would have to generate list or dictionary ahead of time > but this will work on any length int up 2 limit of int does not pad > with zeros on most significant end to word length. > > n=input() > l=[] > while(n>0): > l.append(str(n&1)); n=n>>1 > > I posted this herehttp://www.uselesspython.com/download.php?script_id=222 > a while back. Thanks all... I will have a look at it soon. Regarding to the 32-bit number, the lenght is variable but it is usually defined at design time... -- http://mail.python.org/mailman/listinfo/python-list
how to use cx_Oracle callfunc
Hi all, I need to know how to use the method callfunc in cx_Oracle. I am trying to get a primary key after an insert via a function call, but I do not know how to pass the return value from the function via the callfunc method. Can anyone help? I also tried the execute(), and callproc(), but to no avail. My function is as below: create or replace function addRow(desc table1.col1%type) return number is id number; begin insert into table1 (description) values (desc) returning table1ID into id; return(id); exception when others then return(-1) end; The code in the callfunc: cur.callfunc("addRow", returnType, param) Question is: - What is returnType and how to I declare that before passing into the function? - How do I define the parameters? I tried the setinputsizes and setoutputsize, but I keep getting errors saying the parameter is incorrectly defined. Please help. Thank. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use cx_Oracle callfunc
On May 11, 11:51 am, Godzilla <[EMAIL PROTECTED]> wrote: > Hi all, > > I need to know how to use the method callfunc in cx_Oracle. I am > trying to get a primary key after an insert via a function call, but I > do not know how to pass the return value from the function via the > callfunc method. Can anyone help? > > I also tried the execute(), and callproc(), but to no avail. My > function is as below: > > create or replace function addRow(desc table1.col1%type) return number > is id number; > begin > insert into table1 (description) values (desc) returning table1ID > into id; > return(id); > exception > when others then return(-1) > end; > > The code in the callfunc: > > cur.callfunc("addRow", returnType, param) > > Question is: > - What is returnType and how to I declare that before passing into the > function? > - How do I define the parameters? > > I tried the setinputsizes and setoutputsize, but I keep getting errors > saying the parameter is incorrectly defined. Please help. Thank. Hello, found a solution in another thread... see http://groups.google.com/group/comp.lang.python/browse_thread/thread/ab13d3364aafdd28/4ca1fde2069ff3da?lnk=st&q=cx_oracle+how+to+setinputsizes&rnum=9&hl=en#4ca1fde2069ff3da for more info. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Deleting objects on the fly
Hello, I wish to know whether I should delete objects created on the fly via the "del obj" statement. I noticed the RAM usage increased whenever the application is being run for a long time. I am creating lots of objects (messages) on the fly for communication between threads. Rather than having python's gc to do the work, does it make a difference if I force a deletion? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Memory leak when creating lots of object
Hello, I have a program that create and pop an object off a queue, but it is experiencing some memory leakage. I have been unable to detect where the memory leakage occur. The strange thing is when i replace the object creation with a plain integer/string, the leak goes away... Here's the code I used as my test: import Queue import threading import time q = Queue.Queue(0) class PDU: def __init__(self, name=''): self.name = name class qTest(threading.Thread): def __init__(self, name=''): threading.Thread.__init__(self) self.name = name self.threadContinue = True def run(self): count = 0 while self.threadContinue: pdu = q.get(True) del pdu count+=1 #print count if q.qsize() == 0: print "Total get in bulk", count count = 0 def stop(self): self.threadContinue = False q.put(1) if __name__ == "__main__": try: qt = qTest() qt.start() loopCount = 1000 while True: for i in range(loopCount): pdu = PDU() ##pdu = 1 q.put(pdu) time.sleep(5) except KeyboardInterrupt: print "Keyboard interrupted. Program exit." except Exception, why: print why if qt.isAlive(): qt.stop() I can see the memory usage increases slowly in Task Manager under XP, but do not know why. Anyone help? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory leak when creating lots of object
On Aug 16, 1:13 am, Paul Moore <[EMAIL PROTECTED]> wrote: > On 14 Aug, 05:57, Godzilla <[EMAIL PROTECTED]> wrote: > > > Hello, > > > I have a program that create and pop an object off a queue, but it is > > experiencing some memory leakage. I have been unable to detect where > > the memory leakage occur. The strange thing is when i replace the > > object creation with a plain integer/string, the leak goes away... > > Here's the code I used as my test: > [...] > > I can see the memory usage increases slowly in Task Manager under XP, > > but do not know why. Anyone help? > > I tried your code on my (Windows XP SP2, Python 2.5) system. No memory > leak here - I left it running for over 5 minutes and memory usage was > static at just under 4MB. > > Do you see memory growth with precisely this code? Over what period? > How much? > > Paul. Hi Paul, I have it running for more than 1 hour... the main application software runs for about 50 days non stops and the memory just keep growing... I have a pdu.py class which has about 130 methods that's been created on the fly. If you substitute the above code of PDU() init with the pdu class from pdu.py, I see a dramatic increase in RAM in python 2.4.4! But not in version 2.5.1. So I upgraded to the latest version... I still see the main application uses more and more memory as the time goes by... What should I do next? Can I force garbage collection manually? If so, how do I do that? -- http://mail.python.org/mailman/listinfo/python-list
Python Oracle 10g odbc blob insertion problem
Dear all, I cannot find a solution for my problem with inserting a blob object (>4000 in length) into an ORACLE database via ODBC. I have tried the two ways of inserting the blob object (a zip file): 1) fp = open("c:/test/test.zip", "r+b") data = fp.read() s = odbc.odbc(cs) qry = s.cursor() qry.execute("Insert into tBlob (data) values ('%s')" % data.encode('hex')) return the error: Input String Too Long Limit: 4096 2) qry.execute("Insert into tBlob (data) values (?)", data.encode('hex')) does not return error, but it does not insert the record correctly. Any help will be fully appreciated... -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Oracle 10g odbc blob insertion problem
On Mar 22, 10:56 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Godzilla wrote: > > Dear all, > > > I cannot find a solution for my problem with inserting a blob object > > (>4000 in length) into an ORACLE database via ODBC. > > > I have tried the two ways of inserting the blob object (a zip file): > > > 1) > > fp = open("c:/test/test.zip", "r+b") > > data = fp.read() > > s = odbc.odbc(cs) > > qry = s.cursor() > > qry.execute("Insert into tBlob (data) values ('%s')" % > > data.encode('hex')) > > > return the error: Input String Too Long Limit: 4096 > > > 2) > > qry.execute("Insert into tBlob (data) values (?)", > > data.encode('hex')) > > > does not return error, but it does not insert the record correctly. > > > Any help will be fully appreciated... > > I would certainly recommend that you think about using the cxOracle > package rather than relying on odbc. Most Orcale users do, with evident > satisfaction. > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC/Ltd http://www.holdenweb.com > Skype: holdenwebhttp://del.icio.us/steve.holden > Recent Ramblings http://holdenweb.blogspot.com- Hide quoted text - > > - Show quoted text - Thanks guys for all your help. Steve, I think I've tried what you have suggested without any luck as well... The statement works fine, but what inserted is not correct... it seems like only the symbol '?' was inserted into the blob field... I will try the suggested cxOracle library in place of odbc as a trial... but I think since 95% of the code is using odbc, it would be hard to convince the team to chance to the new library... anyway, I will let you know how it goes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Oracle 10g odbc blob insertion problem
On Mar 23, 4:38 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On 22 Mar 2007 05:36:46 -0700, "Godzilla" <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > Steve, I think I've tried what you have suggested without any luck as > > well... The statement works fine, but what inserted is not correct... > > it seems like only the symbol '?' was inserted into the blob field... > > You didn't have a set of 's around the ?, did you? Parameter > substitution will add needed quotes on its own rather than you having to > put in quotes. > > Also, though I find no documentation on it, odbc module cursors have > setinputsizes() and setoutputsizes() methods -- perhaps that could > change things... OTOH: the db-api 1.0 PEP (which is, it seems, what odbc > module follows) says they may be do-nothing methods. > -- > WulfraedDennis Lee Bieber KD6MOG > [EMAIL PROTECTED] [EMAIL PROTECTED] > HTTP://wlfraed.home.netcom.com/ > (Bestiaria Support Staff: [EMAIL PROTECTED]) > HTTP://www.bestiaria.com/ Gidday Dennis, Thank you for your suggestion. I have found those two functions you mentioned, and there were not much or no documentation for those functions... I used both function and they pretty much do nothing for me... -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Oracle 10g odbc blob insertion problem
On Mar 23, 4:38 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On 22 Mar 2007 05:36:46 -0700, "Godzilla" <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > Steve, I think I've tried what you have suggested without any luck as > > well... The statement works fine, but what inserted is not correct... > > it seems like only the symbol '?' was inserted into the blob field... > > You didn't have a set of 's around the ?, did you? Parameter > substitution will add needed quotes on its own rather than you having to > put in quotes. > > Also, though I find no documentation on it, odbc module cursors have > setinputsizes() and setoutputsizes() methods -- perhaps that could > change things... OTOH: the db-api 1.0 PEP (which is, it seems, what odbc > module follows) says they may be do-nothing methods. > -- > WulfraedDennis Lee Bieber KD6MOG > [EMAIL PROTECTED] [EMAIL PROTECTED] > HTTP://wlfraed.home.netcom.com/ > (Bestiaria Support Staff: [EMAIL PROTECTED]) > HTTP://www.bestiaria.com/ Everything seems to work fine right now... thanks all of you for helping... Have a great day.. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Oracle 10g odbc blob insertion problem
On Mar 23, 9:50 am, Steve Holden <[EMAIL PROTECTED]> wrote: > Godzilla wrote: > > On Mar 23, 4:38 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > >> On 22 Mar 2007 05:36:46 -0700, "Godzilla" <[EMAIL PROTECTED]> > >> declaimed the following in comp.lang.python: > > >>> Steve, I think I've tried what you have suggested without any luck as > >>> well... The statement works fine, but what inserted is not correct... > >>> it seems like only the symbol '?' was inserted into the blob field... > >> You didn't have a set of 's around the ?, did you? Parameter > >> substitution will add needed quotes on its own rather than you having to > >> put in quotes. > > >> Also, though I find no documentation on it, odbc module cursors > >> have > >> setinputsizes() and setoutputsizes() methods -- perhaps that could > >> change things... OTOH: the db-api 1.0 PEP (which is, it seems, what odbc > >> module follows) says they may be do-nothing methods. > >> -- > >> WulfraedDennis Lee Bieber KD6MOG > >> [EMAIL PROTECTED] [EMAIL PROTECTED] > >> HTTP://wlfraed.home.netcom.com/ > >> (Bestiaria Support Staff: [EMAIL PROTECTED]) > >> HTTP://www.bestiaria.com/ > > > Everything seems to work fine right now... thanks all of you for > > helping... Have a great day.. > > Have you any idea what fixed the problem? > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC/Ltd http://www.holdenweb.com > Skype: holdenwebhttp://del.icio.us/steve.holden > Recent Ramblings http://holdenweb.blogspot.com- Hide quoted text - > > - Show quoted text - Hi Steve, I guess Dennis and yourself pointed me to the right direction; no need the 's around ? and also the parameter substitution requires tuple. I.e.: qry.execute("Insert into tBlob (data) values (?)", (data.encode('hex'),)) Thanks again guys... it's been greatly appreciated by the team here as well. -- http://mail.python.org/mailman/listinfo/python-list
Create new processes over telnet in XP
Hello, How do you create/spawn new processes in XP over telnet using python? I.e. I would like to create a new process and have it running in the background... when I terminate the telnet connection, I would what the spawned processes to keep running until I shut it off... I got the os.popen method to spawn a new process running in the backgroun, but not over telnet... tried os.popen[2, 3, 4] and also subprocesses.popen without any luck... Any help will be appreciated... thankyou. -- http://mail.python.org/mailman/listinfo/python-list
Re: Create new processes over telnet in XP
On Mar 24, 12:57 am, "Rob Wolfe" <[EMAIL PROTECTED]> wrote: > Godzilla wrote: > > Hello, > > > How do you create/spawn new processes in XP over telnet using python? > > I.e. I would like to create a new process and have it running in the > > background... when I terminate the telnet connection, I would what the > > spawned processes to keep running until I shut it off... > > > I got the os.popen method to spawn a new process running in the > > backgroun, but not over telnet... tried os.popen[2, 3, 4] and also > > subprocesses.popen without any luck... > > I don't know what kind of OS there is on that remote host you telnet > to. > The idea boils down to appropriate using of methods > `read_until` and `write` from class `telnetlib.Telnet`. > > For more complicated stuff you can consider using pyexpect. > > Here is a small example of connecting to HP-UX. > You can adjust that to your needs. > > > import telnetlib, time > > def login(tn, login, passwd, prompt): > tn.read_until("login: ") > tn.write(login + "\n") > if passwd: > tn.read_until("Password: ") > tn.write(passwd + "\n") > tn.read_until(prompt) > time.sleep(2) > print "logged in" > > def run_proc(tn, progname): > tn.write("nohup %s &\n" % progname) > tn.write("exit\n") > print "program <%s> running" % progname > > def kill_proc(tn, login, prompt, progname): > tn.write("ps -u %s\n" % login) > buf = tn.read_until(prompt) > pid = get_pid(buf, progname) > if not pid: > print "program <%s> not killed" % progname > tn.write("exit\n") > return > tn.write("kill -TERM %s\n" % pid) > tn.write("exit\n") > print "program <%s> killed" % progname > > def get_pid(buf, progname): > pid, comm = None, None > for line in buf.split("\n"): > try: > pid, _, _, comm = line.split() > except ValueError: > continue > if comm == progname: > return pid > > tn = telnetlib.Telnet(HOST, PORT) > #tn.set_debuglevel(1) > login(tn, "login", "passwd", "/home/user") > run_proc(tn, "python ~/test.py") > #kill_proc(tn, "login", "/home/user", "python") > > > -- > HTH, > Rob Thanks guys for your input... Rob, I will give your example a go soon and tell you how i go... Have a nice day... -- http://mail.python.org/mailman/listinfo/python-list
Re: Create new processes over telnet in XP
On Mar 24, 12:57 am, "Rob Wolfe" <[EMAIL PROTECTED]> wrote: > Godzilla wrote: > > Hello, > > > How do you create/spawn new processes in XP over telnet using python? > > I.e. I would like to create a new process and have it running in the > > background... when I terminate the telnet connection, I would what the > > spawned processes to keep running until I shut it off... > > > I got the os.popen method to spawn a new process running in the > > backgroun, but not over telnet... tried os.popen[2, 3, 4] and also > > subprocesses.popen without any luck... > > I don't know what kind of OS there is on that remote host you telnet > to. > The idea boils down to appropriate using of methods > `read_until` and `write` from class `telnetlib.Telnet`. > > For more complicated stuff you can consider using pyexpect. > > Here is a small example of connecting to HP-UX. > You can adjust that to your needs. > > > import telnetlib, time > > def login(tn, login, passwd, prompt): > tn.read_until("login: ") > tn.write(login + "\n") > if passwd: > tn.read_until("Password: ") > tn.write(passwd + "\n") > tn.read_until(prompt) > time.sleep(2) > print "logged in" > > def run_proc(tn, progname): > tn.write("nohup %s &\n" % progname) > tn.write("exit\n") > print "program <%s> running" % progname > > def kill_proc(tn, login, prompt, progname): > tn.write("ps -u %s\n" % login) > buf = tn.read_until(prompt) > pid = get_pid(buf, progname) > if not pid: > print "program <%s> not killed" % progname > tn.write("exit\n") > return > tn.write("kill -TERM %s\n" % pid) > tn.write("exit\n") > print "program <%s> killed" % progname > > def get_pid(buf, progname): > pid, comm = None, None > for line in buf.split("\n"): > try: > pid, _, _, comm = line.split() > except ValueError: > continue > if comm == progname: > return pid > > tn = telnetlib.Telnet(HOST, PORT) > #tn.set_debuglevel(1) > login(tn, "login", "passwd", "/home/user") > run_proc(tn, "python ~/test.py") > #kill_proc(tn, "login", "/home/user", "python") > > > -- > HTH, > Rob Rob, I would be logging into another XP machine to do some software installation... the code you provided, correct me if I'm wrong, seems to work under Unix/Linux. Any idea how to do the equivalent in XP? -- http://mail.python.org/mailman/listinfo/python-list
Queue get timeout parameter question
Dear all, I have been using the queue module for a multithreaded environment and things seem to work well... until we had a requirement for the application to be able to time sync to the server. With the time sync, it actually disorientated the timeout in the queue's get() method... e.g. get(item, 2.0) After the time sync, say 15 seconds backward, the thread is sitting on that get() method for a total of 17 seconds. We can only sync the device once per day and the time can drift up to 15 seconds per day!! I had tried to get around this problem by having a sleep(2) (sleep is not local system time dependant) just before the get(), but that will slow down the application too much. Anyone knows a solution to this problem or an alternative method? -- http://mail.python.org/mailman/listinfo/python-list
Re: Queue get timeout parameter question
On Apr 10, 2:20 pm, Paul Rubin <http://[EMAIL PROTECTED]> wrote: > "Godzilla" <[EMAIL PROTECTED]> writes: > > After the time sync, say 15 seconds backward, the thread is sitting on > > that get() method for a total of 17 seconds. We can only sync the > > device once per day and the time can drift up to 15 seconds per day!! > > Try to avoid syncing lke that. System clocks drift but the drift > rates tend to be constant, so there are schemes for gradually slowing > down or speeding up the system clock in order to keep it synchronized > with an external reference. > > > Anyone knows a solution to this problem or an alternative method? > > http://www.ntp.org Hi Paul, Ok... But I'm afraid no syncing is not an option for the device... -- http://mail.python.org/mailman/listinfo/python-list
Re: Queue get timeout parameter question
On Apr 10, 5:38 pm, Thomas Krüger <[EMAIL PROTECTED]> wrote: > Godzilla schrieb: > > > > > > > I have been using the queue module for a multithreaded environment and > > things seem to work well... until we had a requirement for the > > application to be able to time sync to the server. With the time sync, > > it actually disorientated the timeout in the queue's get() method... > > e.g. > > > get(item, 2.0) > > > After the time sync, say 15 seconds backward, the thread is sitting on > > that get() method for a total of 17 seconds. We can only sync the > > device once per day and the time can drift up to 15 seconds per day!! > > I had tried to get around this problem by having a sleep(2) (sleep is > > not local system time dependant) just before the get(), but that will > > slow down the application too much. > > > Anyone knows a solution to this problem or an alternative method? > > I was fixing a serious time drift problem on Linux lately. If your > server runs on Linux I can give you some hints: > > - set the system clock > - delete /etc/adjtime and resync system time and hardware time > "hwclock --systohc" > - on some distributions you may have to reboot > - give it some time to see if it is still drifting > - if only the system clocks drifts (see output of "hwclock; date") > you may have a timer related kernel problem. This may help: > * deactivate ACPI via kernel boot parameter > * change timer frequency > * try different setting for all timer related stuff like > CONFIG_HPET_TIMER or CONFIG_X86_PM_TIMER > > Thomas > > -- > sinature:http://nospam.nowire.org/signature_usenet.png- Hide quoted text - > > - Show quoted text - Thanks Thomas, I'm not running Linux but I will take some of your pointers as a guide. Cheers mate. -- http://mail.python.org/mailman/listinfo/python-list
Anomaly in time.clock()
Hello, I have been reading a thread about time.clock() going backward, which is exactly what I am seeing... the thread generally leaning toward the problem is caused by multi-processor machines. But I am seeing it at a single CPU computer, and running XP. The error I am seeing between two very close invokation of time.clock() is always around 3.5 seconds! This is enough to throw a lot of the timing requirement in the software out of the window... this is a fairly serious problem. A quick fix will be to capture the time.clock() going backward 3.5 seconds, and then adjust rest of the system accordingly. But I don't feel like this is a good way around this problem. I was using time.time() before switching to time.clock(). The reason I changed is because I need a way to calculate elapsed time independent of system time. Should I just stick with time.time() instead? Or is there another way to calculate elapsed time accurately, independent of system time being changed? -- http://mail.python.org/mailman/listinfo/python-list
Re: Anomaly in time.clock()
Thanks Roel. If there is a way to pass in the PRESERVE_PRECISION constant in the python time.clock library, that would be great. But I'm afraid it's not possible. I think I will change away from using time.clock() from now on... seems too edgy to me. Thank you for sharing your experience with me nonetheless. Cheers mate. -- http://mail.python.org/mailman/listinfo/python-list
Re: Anomaly in time.clock()
Hi John, I am using time.clock to calculate the elapsed time. Below is an example of what I was trying to do: import time import thread class elapseTime: def __init__(self, name=''): self.name = name self.timeStamp = None self.checkTimeFlag = False thread.start_new_thread(self.elapsedTime, ()) def setTime(self, state): if state == 1: self.checkTimeFlag = True self.timeStamp = time.clock() else: self.checkTimeFlag = False def elapsedTime(self): while True: curTime = time.clock() if self.checkTimeFlag: if (curTime - self.timeStamp) > 1.0: print "Elapsed time greater than 1 second. Actual Elapsed Time", round(curTime-self.timeStamp, 3) self.checkTimeFlag = False prevTime = curTime time.sleep(0.05) obj = elapseTime() while True: obj.setTime(1) time.sleep(10) But the time.clock() sometimes return a value of between -3.5 to -4.5 seconds backward. Note that not all computers are behaving the same. I have not experience the same problem with the computer at home. -- http://mail.python.org/mailman/listinfo/python-list
Re: Anomaly in time.clock()
Thanks Ross and John for your help. I apologise for the code I posted earlier not being the full picture of what I was trying to achieve. I had instantiated multiple instances of elapseTime class and each of them gets called approximately the same time. Below is the updated code: import time import thread import Queue printq = Queue.Queue(0) class elapseTime: def __init__(self, name=''): self.name = name self.timeStamp = None self.checkTimeFlag = False thread.start_new_thread(self.elapsedTime, ()) def setTime(self, state): if state == 1: self.checkTimeFlag = True self.timeStamp = time.clock() else: self.checkTimeFlag = False def elapsedTime(self): prevTime = time.clock() while True: curTime = time.clock() timeDiff = (curTime - prevTime) if timeDiff < 0.0: printq.put_nowait('time.clock() has gone backward!!! Time Diff '+str(timeDiff)) if self.checkTimeFlag: if (curTime - self.timeStamp) > 1.0: printq.put_nowait(self.name+", actual Elapsed Time"+str(round(curTime-self.timeStamp, 3))) self.checkTimeFlag = False prevTime = curTime time.sleep(0.05) def printmgr(): while True: print printq.get(True) # Print thread thread.start_new_thread(printmgr, ()) objList = [] for i in range(10): objList.append(elapseTime("obj"+str(i))) while True: for i in range(len(objList)): objList[i].setTime(1) time.sleep(10) print When I run the above code long enough in the PC I see the 'time.clock() has gone backward!!!' statement being printed once in a while. I have been reading a thread about invoking time.clock() at close proximity caused the 'time warp' problem. John, the PC experiencing this problem is a single core Intel Celeron 1GHz, XP SP2. The PC at home is a AMD Dual Core XP SP2. -- http://mail.python.org/mailman/listinfo/python-list
Re: Anomaly in time.clock()
Just found out that win32api.GetTickCount() returns a tick count in milli-second since XP started. Not sure whether that is reliable. Anyone uses that for calculating elapsed time? -- http://mail.python.org/mailman/listinfo/python-list