Skip to content
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

Catch time(), ftime(), localtime() and clock() errors #58055

Closed
vstinner opened this issue Jan 24, 2012 · 9 comments
Closed

Catch time(), ftime(), localtime() and clock() errors #58055

vstinner opened this issue Jan 24, 2012 · 9 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@vstinner
Copy link
Member

BPO 13847
Nosy @abalkin, @vstinner
Files
  • time_error.patch
  • 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:

    assignee = None
    closed_at = <Date 2012-01-31.22:38:15.283>
    created_at = <Date 2012-01-24.01:06:28.753>
    labels = ['type-feature', 'library']
    title = 'Catch time(), ftime(), localtime() and clock() errors'
    updated_at = <Date 2012-01-31.22:38:15.282>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2012-01-31.22:38:15.282>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-01-31.22:38:15.283>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2012-01-24.01:06:28.753>
    creator = 'vstinner'
    dependencies = []
    files = ['24308']
    hgrepos = []
    issue_num = 13847
    keywords = ['patch']
    message_count = 9.0
    messages = ['151871', '152044', '152049', '152052', '152053', '152055', '152056', '152064', '152283']
    nosy_count = 3.0
    nosy_names = ['belopolsky', 'vstinner', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'needs patch'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue13847'
    versions = ['Python 3.3']

    @vstinner
    Copy link
    Member Author

    Attach patch catchs errors on time(), ftime(), localtime() and clock(). It changes floattime() and _Py_gettimeofday() signature: result now indicates if an error occurred or not, and these function now directly raise an exception.

    Catching time() error is maybe overflow: modern version of its manual page don't mention errors.

    @vstinner vstinner added the stdlib Python modules in the Lib dir label Jan 24, 2012
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 26, 2012

    New changeset 9ee4a104e33d by Victor Stinner in branch 'default':
    Issue bpo-13847: time.localtime() and time.gmtime() now raise an OSError instead
    http://hg.python.org/cpython/rev/9ee4a104e33d

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 26, 2012

    New changeset 94b7eb09d0b3 by Victor Stinner in branch 'default':
    Issue bpo-13847: time.clock() now raises a RuntimeError if the processor time used
    http://hg.python.org/cpython/rev/94b7eb09d0b3

    @vstinner
    Copy link
    Member Author

    I added tests on localtime() and clock().

    I read more carefully time(), ftime() and gettimeofday() manpage: it is not possible that they fail if the argument is an invalid pointer, the current code is correct.

    I don't want to backport changes because they are incompatible.

    --

    There is a failure on FreeBSD 8.2:

    ======================================================================
    FAIL: test_localtime_failure (test.test_time.TimeTestCase)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/usr/home/buildbot/buildarea/3.x.krah-freebsd/build/Lib/test/test_time.py", line 358, in test_localtime_failure
        self.assertRaises(OSError, time.localtime, invalid_time_t)
    AssertionError: OSError not raised by localtime

    http://www.python.org/dev/buildbot/all/builders/AMD64%20FreeBSD%208.2%203.x/builds/1746/steps/test/logs/stdio

    test_localtime_failure() should be removed or at least skipped on FreeBSD, except if someone knows another invalid time_t value on this platform.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 26, 2012

    New changeset 516d42a6e518 by Victor Stinner in branch 'default':
    Issue bpo-13847: Fix test_mktime(), time.localtime() now raises OSError
    http://hg.python.org/cpython/rev/516d42a6e518

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 27, 2012

    New changeset 856f0864437a by Victor Stinner in branch 'default':
    Issue bpo-13847: Make test_localtime_failure() more robust
    http://hg.python.org/cpython/rev/856f0864437a

    @vstinner
    Copy link
    Member Author

    The issue should be done with the last commit.

    @vstinner
    Copy link
    Member Author

    There is still an error on Windows:

    ======================================================================
    FAIL: test_localtime_failure (test.test_time.TimeTestCase)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "D:\Buildslave\3.x.moore-windows\build\lib\test\test_time.py", line 364, in test_localtime_failure
        self.assertRaises(OSError, time.gmtime, invalid_time_t)
    AssertionError: OSError not raised by gmtime

    http://www.python.org/dev/buildbot/all/builders/x86%20XP-5%203.x/builds/4074/steps/test/logs/stdio

    time.ctime() uses localtime() internally, whereas time.gmtime() doesn't. Another time should maybe be written (to test a different time_t value). Or remove completly the whole test because it is not reliable :-)

    @vstinner vstinner reopened this Jan 27, 2012
    @terryjreedy terryjreedy added the type-feature A feature request or enhancement label Jan 27, 2012
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 29, 2012

    New changeset 5b42aefb8969 by Victor Stinner in branch 'default':
    Issue bpo-13847: Fix test_time, time.gmtime() doesn't use localtime()
    http://hg.python.org/cpython/rev/5b42aefb8969

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants