Threads and time.strptime()

Maximilian Michel maximilian.michel at gmail.com
Tue Jul 4 04:24:42 EDT 2006


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




More information about the Python-list mailing list