Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 157015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:25:42+00:00 2026-05-11T10:25:42+00:00

I am stuck with a fairly complex Python module that does not return useful

  • 0

I am stuck with a fairly complex Python module that does not return useful error codes (it actually fails disturbingly silently). However, the underlying C library it calls sets errno.

Normally errno comes in over OSError attributes, but since I don’t have an exception, I can’t get at it.

Using ctypes, libc.errno doesn’t work because errno is a macro in GNU libc. Python 2.6 has some affordances but Debian still uses Python 2.5. Inserting a C module into my pure Python program just to read errno disgusts me.

Is there some way to access errno? A Linux-only solution is fine, since the library being wrapped is Linux-only. I also don’t have to worry about threads, as I’m only running one thread during the time in which this can fail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:25:43+00:00Added an answer on May 11, 2026 at 10:25 am

    Update: On Python 2.6+, use ctypes.get_errno().

    Python 2.5

    Belowed code is not reliable (or comprehensive, there are a plefora of ways errno could be defined) but it should get you started (or reconsider your position on a tiny extension module (after all on Debian python setup.py install or easy_install should have no problem to build it)). From http://codespeak.net/pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py

    if not hasattr(ctypes, 'get_errno'):     # Python 2.5 or older     if sys.platform == 'win32':         standard_c_lib._errno.restype = ctypes.POINTER(ctypes.c_int)         def _where_is_errno():             return standard_c_lib._errno()      elif sys.platform in ('linux2', 'freebsd6'):         standard_c_lib.__errno_location.restype = ctypes.POINTER(ctypes.c_int)         def _where_is_errno():             return standard_c_lib.__errno_location()      elif sys.platform in ('darwin', 'freebsd7'):         standard_c_lib.__error.restype = ctypes.POINTER(ctypes.c_int)         def _where_is_errno():             return standard_c_lib.__error()     ctypes.get_errno = lambda: _where_is_errno().contents.value  

    Where standard_c_lib:

    def get_libc_name():     if sys.platform == 'win32':         # Parses sys.version and deduces the version of the compiler         import distutils.msvccompiler         version = distutils.msvccompiler.get_build_version()         if version is None:             # This logic works with official builds of Python.             if sys.version_info < (2, 4):                 clibname = 'msvcrt'             else:                 clibname = 'msvcr71'         else:             if version <= 6:                 clibname = 'msvcrt'             else:                 clibname = 'msvcr%d' % (version * 10)          # If python was built with in debug mode         import imp         if imp.get_suffixes()[0][0] == '_d.pyd':             clibname += 'd'          return clibname+'.dll'     else:         return ctypes.util.find_library('c')  # Make sure the name is determined during import, not at runtime libc_name = get_libc_name()  standard_c_lib = ctypes.cdll.LoadLibrary(get_libc_name()) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 83k
  • Answers 83k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer couple thoughts... is the class name acctually changing? check this… May 11, 2026 at 4:55 pm
  • Editorial Team
    Editorial Team added an answer I suggest adding a switch in your preamble when generating… May 11, 2026 at 4:55 pm
  • Editorial Team
    Editorial Team added an answer I'm still not sure I understand, but can't you just… May 11, 2026 at 4:55 pm

Related Questions

I am having trouble with my Visual Studio 2005 IntelliSense for some time now.
I've accepted an answer, but sadly, I believe we're stuck with our original worst
I need to count the number of elements in an XML file that have
Suppose I want to create a set of observers based on type. That is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.