Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to get time.strptime()?

Reply
Thread Tools

How to get time.strptime()?

 
 
Gnarlodious
Guest
Posts: n/a
 
      12-26-2012
Error: AttributeError: 'module' object has no attribute '_strptime'

This problem is driving me crazy. It only happens in Python 3.3.0, while on my server running 3.1.3 it behaves as expected. When I try to access time.strptime() it errors with

AttributeError: 'module' object has no attribute '_strptime'.

This error only occurs under mod_wsgi, when running as a one-shot webapp it behaves normally. All other functionalities of the time module are normal.

If anyone could explain why it thinks I want an underscored name maybe it would help.

Thanks.

-- Gnarlie
 
Reply With Quote
 
 
 
 
Chris Rebert
Guest
Posts: n/a
 
      12-26-2012
On Wednesday, December 26, 2012, Gnarlodious wrote:

> Error: AttributeError: 'module' object has no attribute '_strptime'
>


Please include the full Traceback, not just the final error message.

This problem is driving me crazy. It only happens in Python 3.3.0, while on
> my server running 3.1.3 it behaves as expected. When I try to access
> time.strptime() it errors with
>
> AttributeError: 'module' object has no attribute '_strptime'.



Might be the wrong `time` module. What's `print time.__file__` output?
Did you perchance create a time.py file in your project?

This error only occurs under mod_wsgi, when running as a one-shot webapp it
> behaves normally. All other functionalities of the time module are normal.
>
> If anyone could explain why it thinks I want an underscored name maybe it
> would help.
>
> Thanks.
>
> -- Gnarlie
> --
> http://mail.python.org/mailman/listinfo/python-list
>



--
Cheers,
Chris
--
http://rebertia.com

 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      12-26-2012
On Wed, 26 Dec 2012 08:33:42 -0800, Gnarlodious wrote:

> Error: AttributeError: 'module' object has no attribute '_strptime'
>
> This problem is driving me crazy. It only happens in Python 3.3.0, while
> on my server running 3.1.3 it behaves as expected. When I try to access
> time.strptime() it errors with
>
> AttributeError: 'module' object has no attribute '_strptime'.

[...]
> If anyone could explain why it thinks I want an underscored name maybe
> it would help.


Perhaps if you were to read the ENTIRE traceback, not just the last line,
you will see something that hints at an explanation. Here is a similar
error:

py> time.strptime(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.3/_strptime.py", line 494, in
_strptime_time
tt = _strptime(data_string, format)[0]
File "/usr/local/lib/python3.3/_strptime.py", line 306, in _strptime
raise TypeError(msg.format(index, type(arg)))
TypeError: strptime() argument 0 must be str, not <class 'NoneType'>


After reading the full traceback, I conclude that the time.strptime
function calls _strptime._strptime. After importing _strptime and looking
at the __file__ attribute, I see that it is a pure-python module. So, to
answer your immediate question:

"explain why it [the time.strptime function] thinks I want an underscored
name"

the answer is, it thinks you want an underscored name because you *do*
need an underscored name. It is part of the implementation of
time.strptime that it delegates some of the work to a private module
_strptime.

As for why that is not available under mod_wsgi module, but is available
when running under the normal Python environment, I have looked at the
_strptime.py source code and nothing stands out to explain why the
_strptime function might not be defined. So that seems like a question
about mod_wsgi. I suggest you start here:

http://code.google.com/p/modwsgi/wiki/WhereToGetHelp

If you do get an answer, please post it here as well, so others in the
future who stumble across this thread will see the answer.

Good luck!



--
Steven
 
Reply With Quote
 
Gnarlodious
Guest
Posts: n/a
 
      12-26-2012
Thanks for the help.
This error only occurs on my devbox which is running Py 3.3.0:

print(time.__file__, file=sys.stderr)
/usr/local/python-3.3.0/frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload/time.so

which looks normal to me.
The server box, which is running Py 3.1.3, says this:
/usr/local/python-3.1.3/frameworks/Python.framework/Versions/3.1/lib/python3.1/lib-dynload/time.so

Also of possible relevance is that my server is running mod_wsgi 3.3, whilemy devbox is running mod_wsgi 3.4. However I had a discussion with Dumpleton who decided it is a Python problem:
https://groups.google.com/forum/#!to...gi/9MF2ixebvfg

I don't know how to get any sort of traceback out of mod_wsgi. The script runs normally as a single-page CGI script but the error only occurs when imported as a module.

Exactly what I am saying is this:
import time
print(time.strptime("00", "%y"), file=sys.stderr)
--> No module named 'time.strptime'

But this works normally:
print(time.time(), file=sys.stderr)
--> 1356549188.368575

I can say this and see 'strptime' in the list of functions:
print(dir(time), file=sys.stderr)
--> ['_STRUCT_TM_ITEMS', '__doc__', '__file__', '__loader__', '__name__', '__package__', 'altzone', 'asctime', 'clock', 'ctime', 'daylight', 'get_clock_info', 'gmtime', 'localtime', 'mktime', 'monotonic', 'perf_counter', 'process_time', 'sleep', 'strftime', 'strptime', 'struct_time', 'time', 'timezone', 'tzname', 'tzset']

So I am stumped.

-- Gnarlie
 
Reply With Quote
 
Nick Cash
Guest
Posts: n/a
 
      12-26-2012
> Error: AttributeError: 'module' object has no attribute '_strptime'
>
> This problem is driving me crazy. It only happens in Python 3.3.0,
> while on my server running 3.1.3 it behaves as expected. When I try to
> access time.strptime() it errors with
>
> AttributeError: 'module' object has no attribute '_strptime'.
>
> This error only occurs under mod_wsgi, when running as a one-shot
> webapp it behaves normally. All other functionalities of the time
> module are normal.


I've run into this issue in the past with Python 2.6 (or maybe 2.7) and mod_python. My problem was that datetime.strptime imported _strptime at runtime, and multiple threads trying to import it at the same time broke an internal import lock.

I was able to work around this by simply importing _strptime myself at server startup time. This may or may not work for you.

See also: http://code.google.com/p/modwsgi/issues/detail?id=177 and http://www.mail-archive.com/python-l...msg248664.html


 
Reply With Quote
 
Gnarlodious
Guest
Posts: n/a
 
      12-27-2012
Nick Cash wrote:

> I was able to work around this by simply importing _strptime myself at server startup time.


THANK YOU! That fixed it, I simply put

import _strptime

in my *.wsgi script. It feels like a kludgy solution, but it works.

I should also mention that I had a similar problem with the "threading" module that I fixed in the same way. This problem occurred inside of sqlite3 because evidently threadlocking has gone standard as of Py 3.3.x

This is problem that has unduly vexed me. When you start learning Python they don't tell you about these sharp edges. Someone needs to explain.

-- Gnarlie
 
Reply With Quote
 
Gnarlodious
Guest
Posts: n/a
 
      12-27-2012
Nick Cash wrote:

> I was able to work around this by simply importing _strptime myself at server startup time.


THANK YOU! That fixed it, I simply put

import _strptime

in my *.wsgi script. It feels like a kludgy solution, but it works.

I should also mention that I had a similar problem with the "threading" module that I fixed in the same way. This problem occurred inside of sqlite3 because evidently threadlocking has gone standard as of Py 3.3.x

This is problem that has unduly vexed me. When you start learning Python they don't tell you about these sharp edges. Someone needs to explain.

-- Gnarlie
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      12-27-2012
On Wed, 26 Dec 2012 19:09:51 -0800, Gnarlodious wrote:

> This is problem that has unduly vexed me. When you start learning Python
> they don't tell you about these sharp edges.



"Hi, I've just started learning Python today, and I have a question. How
do I print a list?"

"Before I answer that question, let me explain to you how to fix a
problem with time.strptime that only occurs when running under mod_wsgi.
Now, I know that you're still struggling with print, haven't even got to
importing modules yet, have no idea what strptime is, and that 99.99% of
Python programmers will never use mod_wsgi in their life, but if we don't
tell you about this right now, in five years time you will complain that
nobody told you about the sharp edges when you started..."

*wink*

A serious question: when should somebody have told you about this sharp
edge, and who should have been responsible to do so?



--
Steven
 
Reply With Quote
 
Roy Smith
Guest
Posts: n/a
 
      12-27-2012
In article <(E-Mail Removed)>,
Gnarlodious <(E-Mail Removed)> wrote:

> This is problem that has unduly vexed me. When you start learning Python they
> don't tell you about these sharp edges. Someone needs to explain.


The same thing happens when you're born. You spend your entire life
figuring out the sharp edges. And then you die.
 
Reply With Quote
 
Mitya Sirenef
Guest
Posts: n/a
 
      12-27-2012
On 12/26/2012 10:09 PM, Gnarlodious wrote:
> This is problem that has unduly vexed me. When you start learning
> Python they don't tell you about these sharp edges. Someone needs to
> explain. -- Gnarlie


In fact, if there were no bugs, there would be no need to explain nor to
pick the
right time / place for explanations. Why doesn't Python warn that it's not
100% perfect? Are people just supposed to "know" this, magically?

--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Serious cache problem - Page_Load get never get called !!! Ryan Park ASP .Net 2 01-03-2005 05:52 PM
Re: use anonymous but get get an authentication box Curt_C [MVP] ASP .Net 2 09-21-2004 06:39 PM
use anonymous but get get an authentication box =?Utf-8?B?U2hhcmlm?= ASP .Net 0 09-21-2004 01:01 PM



Advertisments