By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,361 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,361 IT Pros & Developers. It's quick & easy.

Threads and time.strptime()

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a

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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.