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

  • SEARCH
  • Home
  • 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 8164125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:14:45+00:00 2026-06-06T19:14:45+00:00

I have a Python application in the bottle web-server that accesses a C shared-object

  • 0

I have a Python application in the bottle web-server that accesses a C shared-object library via the ctypes Python module on a Linux platform. The C so-lib opens a device node (/dev/myhwdev) and asserts an IOCTL function against the device’s file descriptor. Although this is a complicated stack, it works great until I wrap the bottle app in Python’s python-daemon context, like so:

# -*- coding: utf-8 -*-
import daemon
import bottle
from bottle import run, route, request

from userlib_via_ctypes_module import *
userlib_grab_device_file_descriptor()

@route('/regread')
def show_regread():
    address = request.query.address or request.forms.address
    length = request.query.length or request.forms.length
    return {'results':assert_ioctl_via_userlib(address, length)}

daemonContext = daemon.DaemonContext(
    detach_process = False
    )
with daemonContext:
    try:
        run(host = '0.0.0.0', port = '80', debug = True)
    except:
        print "(E) Bottle web-service was stopped.\n";

Simply commenting out the with daemonContext line (and correcting indentation) allows this code to work correctly (i.e., serves the correct JSON result). However, within the daemonContext, print statements in my userlib show that the file-descriptor for my device node is opened correctly, but the ioctl function silently fails with an error code of -1.

Closing the device’s file-descriptor and reopening it (in either the userlib code or the above route handler) allow the command to work correctly – once. But, the daemon and bottle server lock up and ignore all further web requests.

Suggestions? Currently, I am ready to give up on the daemon module, since everything works fine with out it.

Thanks!

  • 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. Editorial Team
    Editorial Team
    2026-06-06T19:14:46+00:00Added an answer on June 6, 2026 at 7:14 pm

    In preparing this question, the answer became obvious to me.

    The userlib_grab_device_file_descriptor() function called a C-level, SO-lib function that opened the file-descriptor for the hardware device node, which was passed to the userlib ioctl function.

    The python-daemon closes ALL file-handles upon entry of the context – including the inherited file-descriptor for the hardware device. The userlib still thought the file-descriptor was valid. At least, it would print the FD in my debug messages as an integer > 2. However, unbeknown to the userlib, the file-handle had indeed been closed, so the IOCTL would just fail silently. I wished there had been a better error message supplied by uclib or the kernel. 🙁

    Anyway, the answer was to move the file-handle opening to the inside of the daemon context, like so:

    ...
    with daemonContext:
        try:
            userlib_grab_device_file_descriptor()   # open fd here
            run(host = '0.0.0.0', port = '80', debug = True)
        except:
            print "(E) Bottle web-service was stopped.\n";
    

    I tried using python-daemon’s files_preserve attribute, but it works on file-descriptor numbers, not filenames. Therefore, after opening the fd, my userlib would have to pass the fd number up to the daemon, so it could exclude the fd before entering the daemon. … I found it easier to open the file-descriptor inside the daemon. 🙂

    Hope this helps someone else. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i supose that i have a server application written in python import bottle
I have a web application build in Django + Python that interact with web
I have a python web application that needs to launch a long running process.
I have a python application which uses a compiled shared library. This library for
I have inherited a windows Python application that communicates with linux RabbitMQ. I need
I have a small web.py Python application that I would like to serve under
I have a multi-process python application (processes are spawned by uwsgi) that needs to
I have the 'luck' of develop and enhance a legacy python web application for
I have an application that uses Django 1.3 installed in python's site-packages. I want
I'm developing a python application and have a question regarding coding it so that

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.