473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Threads and time.strptime()

Hi all,

I have an interesting problem:
I have written code, that reads a logfile and parses it for date string
(Thu Jun 29 14:01:23 2006).
Standalone everthing works fine, all is recognized.

But if I let the same code run in a thread, with the same file as input
I get the following error:
....
File "sensor.py", line 158, in gotData
t = time.strptime(s)
File "/usr/lib/python2.4/_strptime.py", line 293, in strptime
raise ValueError("time data did not match format: data=%s fmt=%s"
%
ValueError: time data did not match format: data=Thu Jun 29 14:01:23
2006 fmt=%a %b %d %H:%M:%S %Y
Has anyone encountered similiar problems? And how did you get around?
Thanks,
Maximilian

Jul 3 '06 #1
4 2306

Maximilian Michel wrote:
Hi all,

I have an interesting problem:
I have written code, that reads a logfile and parses it for date string
(Thu Jun 29 14:01:23 2006).
Standalone everthing works fine, all is recognized.

But if I let the same code run in a thread, with the same file as input
I get the following error:
do you read the logfile in the thread too or pass the read that to the
thread?

Jul 4 '06 #2
On 3/07/2006 6:57 PM, Maximilian Michel wrote:
Hi all,

I have an interesting problem:
I have written code, that reads a logfile and parses it for date string
(Thu Jun 29 14:01:23 2006).
Standalone everthing works fine, all is recognized.

But if I let the same code run in a thread, with the same file as input
I get the following error:
...
File "sensor.py", line 158, in gotData
t = time.strptime(s)
File "/usr/lib/python2.4/_strptime.py", line 293, in strptime
raise ValueError("time data did not match format: data=%s fmt=%s"
%
ValueError: time data did not match format: data=Thu Jun 29 14:01:23
2006 fmt=%a %b %d %H:%M:%S %Y
Possibilities:

(1) The thread implementation has acquired extra characters (whitespace
or \x00).

(2) The thread implementation has changed to a locale that doesn't have
"Thu" & "Jun" as day/month name abbreviations.

Try inserting
print "strptime(%r); locale: %r" % (s, locale.getlocale())
before your call to strptime()

HTH,
John
Jul 4 '06 #3
The parsing thread reads also the file from the disk.
placid wrote:
Maximilian Michel wrote:
Hi all,

I have an interesting problem:
I have written code, that reads a logfile and parses it for date string
(Thu Jun 29 14:01:23 2006).
Standalone everthing works fine, all is recognized.

But if I let the same code run in a thread, with the same file as input
I get the following error:

do you read the logfile in the thread too or pass the read that to the
thread?
Jul 4 '06 #4
Thank you so much!
(2) was the reason!
Without threads, locale.getlocale() returns (None, None), while calling
it in this thread gives back ('de_DE', 'iso-8859-15').
I'm still curious, why this occurs, but anyway it's fixable with
setlocale(LC_ALL, 'C'); so normally Python doesn't set locales
according to my system environment, but in a separate thread it does...
strange (or i just didn't set something correctly?).

Thank you so much!

max
John Machin wrote:
On 3/07/2006 6:57 PM, Maximilian Michel wrote:
Hi all,

I have an interesting problem:
I have written code, that reads a logfile and parses it for date string
(Thu Jun 29 14:01:23 2006).
Standalone everthing works fine, all is recognized.

But if I let the same code run in a thread, with the same file as input
I get the following error:
...
File "sensor.py", line 158, in gotData
t = time.strptime(s)
File "/usr/lib/python2.4/_strptime.py", line 293, in strptime
raise ValueError("time data did not match format: data=%s fmt=%s"
%
ValueError: time data did not match format: data=Thu Jun 29 14:01:23
2006 fmt=%a %b %d %H:%M:%S %Y

Possibilities:

(1) The thread implementation has acquired extra characters (whitespace
or \x00).

(2) The thread implementation has changed to a locale that doesn't have
"Thu" & "Jun" as day/month name abbreviations.

Try inserting
print "strptime(%r); locale: %r" % (s, locale.getlocale())
before your call to strptime()

HTH,
John
Jul 4 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
1
by: Michele Simionato | last post by:
I have strings representing UTC dates and I want to convert them in time tuples using time.strptime. I have an issue with daylight savings. For instance Tue Sep 14 06:06:15 2004 is converted...
10
by: Maksim Kasimov | last post by:
hi all, sorry if i'm reposting why time.strptime and time.localtime returns tuple with different DST (9 item of the tuple)? is there some of setting to fix the problem? Python 2.2.3 (#1, May...
2
by: Robert | last post by:
A certain DAV server reports a time stamp as "Tues, 30 Aug 2005 20:48:31" ( but not "Tue, ..." as usual) This produces the error below. >>> time.strptime("Tue, 30 Aug 2005 20:48:31","%a, %d...
3
by: Ilja Booij | last post by:
Hi all, I have some trouble with the following: I'm getting a time string, in YYYY-MM-DD HH:mm:ss format, which I need to translate into a string with DD-Mon-YYYY HH:mm:ss +HHMM, where the...
1
by: davelist | last post by:
I'm guessing there is an easy way to do this but I keep going around in circles in the documentation. I have a time stamp that looks like this (corresponding to UTC time): start_time =...
5
by: rouven | last post by:
Hi, i am trying to convert that time format '05:26:40 Jun 19, 2007 PDT' into mysql compatible format like YYYY-MM-DD HH:MM:SS. the code i tried was: from datetime import datetime from time...
2
by: Joshua J. Kugler | last post by:
I am getting results like these with the time module: %S'))) 1173610800 %S'))) 1173610800 '2007-03-11 03:00:00' I know it probably has something to do with daylight savings, but how can I...
2
by: barronmo | last post by:
I'm trying to get the difference in dates using the time module rather than datetime because I need to use strptime() to convert a date and then find out how many weeks and days until that date. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.