Threads and time.strptime()

  • Thread starter Maximilian Michel
  • Start date
M

Maximilian Michel

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
 
P

placid

Maximilian said:
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?
 
J

John Machin

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
 
M

Maximilian Michel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top