-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pure Python implementation of time module to CPython #53737
Comments
The original RFE at bpo-7989 was: """ See msg99774. I have changed bpo-7989 to cover datetime only because I argued that as a thin wrapper around C library calls, this module is an exception to the general rule that pure python implementations are a good idea. See msg107303. No I realize that in order to break circular dependency between time and datetime modules, it will be helpful to create an _time module that would provide lower than time module access to system facilities and datetime and time modules would be use _time module to implement higher level interfaces either in C or in Python. I believe _time module should become the home of the gettimeofday() method and pure python implementation of time.time() will be def time()
s, us = _time.gettimeofday()
return s + 1e-6 * us Similarly time.sleep() can be implemented in terms of lower level POSIX nanosleep() method. Lower level localtime() function can provide access to tm_zone and tm_gmtoff members of struct tm (where available) without concerns about backward compatibility. |
Just for understanding: Why are you calling the ticket "*Add* pure Python implementation of time The same argument as for the datetime module applies: you can *add* Both datetime and time module functionalities need to be as fast as Python C function calls are still a lot faster than Python function |
These changes are very aggressive and may be doing more harm than good. |
On Fri, Aug 6, 2010 at 3:44 AM, Marc-Andre Lemburg
I have deliberately made the title similar to bpo-7989 so that it is The current situation has several problems:
I completely agree. Actually my outline in the first post is
Absolutely. In fact this proposal will open the door to implementing BTW, this brings a point that I think I missed when I introduced
Brett addressed this point responding to my own concerns in msg107295 |
Why not introducing a new function in time module? Other people may benefit from this.
Why not creating a new function giving access to all tm attributes? Eg. time.localtime_gmaware()?
What about time_strftime()? It is 170 lines long: will it be moved to _basictime.c? You have to keep the code filling the "struct tm" structure in (_)timemodule.c. |
On Thu, Aug 12, 2010 at 10:26 PM, STINNER Victor <report@bugs.python.org> wrote:
I agree. See bpo-9079. We can do that. I'll experiment with this approach within bpo-9527.
No, I don't want time_strftime in _basictime. I want |
BDFL and python-dev were opposed to this idea. |
@alanjds: Why do you add Python 2.7 version to this issue? |
@victor it doesn't really matter why since it is an incorrect classification. This issue in no way involves Python 2.7 since we will not backport any modules to Python 2.7. |
@Haypo: Because it affects version 2.7 too. @victor: Even since we will not backport any modules to Python 2.7, is not worth to sign that this affects it too? Even wontfix or rejected, it affects, does not? Have I made something wrong? Sorry to be so newbie about this. Long explanation: Is not easy to change/extend datetime, as stated by several other before. Searching the bugs for 2.x only does not shows that someone else already care about this issue AND that it exists at 2.x too. I am getting a hard time trying to do some BDD with c-based datetime because I cannot mock it easily to force datetime.datetime.now() to return a desired value, making almost impossible to test time-based code, like the accounting system that I am refactoring right now. Another solution would be to "open" C-based classes to allow modification, that is not planned to be into near future Python versions AFAIK. I came to fill a new bug with all this, but then found this one that is already mature enough, with even BDFL and python-dev opinion. Then my (maybe pointless) plan was to gather more arguments favor to change into python-based datetime, but you replied first... |
(noticed a typo at the start of my last msg: @victor should be @brett.cannon) |
Alan Justino wrote:
It's usually better to use a central helper get_current_time() in |
Alan: the Versions field is used to mark versions that will get a patch, not all versions affected. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: