It’s very weird, I have never had issue working with strptime before.
Here is a copy of the script:
#Get results of query
oldData = system.db.runPrepQuery(query, )
oldData = system.dataset.toPyDataSet(oldData)
#Will use historical data for comparison later
histData = 
#Loop through results of query to build dataset
for row in range(oldData.rowCount):
status = oldData.getValueAt(row, 'Status')
timestamp = oldData.getValueAt(row, 'Timestamp')
timestamp = str(timestamp)
#Manual entries do not contain milliseconds
if '.' in timestamp:
timestamp = timestamp[0:timestamp.find('.')]
#Print before loop to see if anything is weird
#Causes infinite loop >:(
timestamp = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
Where is this script being called from? A property change event? Most infinite loops I’ve run into (or caused) have been circular property change events. Property Change Event A → changes some property that triggers Property Change Event B → changes some property that triggers Property Change Event A and so on
Though looking at your script, I don’t see how that would be the case. What does your script end up doing with histData? Is there more to the script? If so post it.
Why use system.db.runPrepQuery() with no parameters? Just use system.db.runQuery() and the results will be returned as a PyDataSet removing the need for the conversion.
Why convert oldData to a PyDataSet and then not use it that way?
#Get results of query
oldData = sysetm.db.runQuery(query)
#Will use historical data for comparison later, List of Dictionaries
histData = 
for row in oldData:
timestamp = system.date.addMillis(row['Timestamp'],-1 * system.date.getMillis(row['Timestamp']))
That being said, it’s obvious that you haven’t shown the entire script, as there is no Import statement and you would need at least that. I suspect that it looks something like import datetime if you changed that to from datetime import datetime you could get rid of the redundant datetime.datetime.* syntax.
I’m also assuming that there is script following this loop, as it doesn’t do anything aside from printing the timestamp. Is it possible that the query is only returning 1 row? What is supposed to happen after this loop?
It looks like this is in an onStartup script on the view Embed/StatusDetail, I’m not sure that is the best place for it, but then I also don’t know what it’s trying to accomplish.
I have an excel vba that generates script transforms for me to save me some typing. This defaults to prep query, its not a big deal really (doesn’t affect my issue)
Yes I use import datetime and yes there are other ways to do this. This does not affect my issue either
I removed all the code after this because its irrelevant. It gets stuck on that line that I mentioned. I did mess up my description. I meant that it runs fine with a comment out through the strptime command, yet with no comment it gets stuck there. Thats why it prints 4 lines (there are 4 rows in the data), yet only prints one with no comment on that line.
I need this on a startup script because it is generated on startup and I need a one time run on startup. Explaining everything would be too detailed and irrelevant, every code after the one mentioned does not run
Okay, I’ll agree, won’t effect the outcome of the script.
There is no reason from this script that I can see that datetime.strptime() should not work, from what I can tell you have used the correct format string, and timestamp is a string which should have a matching format (Based on the print in the provided screen shot).
Perhaps wrap it in a try...except to see if it might through an error there?