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 8232207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:45:15+00:00 2026-06-07T17:45:15+00:00

I have a threaded C program that I want to launch using a Python

  • 0

I have a threaded C program that I want to launch using a Python GUI in a Unix environment. I want to be able to change the state of the GUI by gathering output from the C program.

For instance, this is output from my C program using printf:

Thread on tile 1: On
Thread on tile 2: OFF
Thread on tile 3: Disable
...
Thread on tile 61: ON

I would update my GUI based on the output. What makes the problem difficult is both my GUI and the C program need to run simultaneously and updates happening in realtime. I also need to be able to send commands to the C program from my GUI.

I’m new to Python, C, and Unix (I know, complete rookie status).
I’ve read up on subprocess, Popen, and pexpect, but not sure how to put it all together of if this is even possible at all.

Thanks in advance

  • 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-07T17:45:17+00:00Added an answer on June 7, 2026 at 5:45 pm

    There’s a toughie. I’ve run into this problem in the past (with no truly satisfactory solution):

    https://groups.google.com/forum/?fromgroups#!topic/comp.lang.python/79uoHgAbg18

    As suggested there, take a look at this custom module:

    http://pypi.python.org/pypi/sarge/0.1
    http://sarge.readthedocs.org/en/latest/

    Edit @Richard (not enough rep to comment): The problem with pipes is that unless they are attached to an interactive terminal, they are fully buffered — meaning that none of the output is passed through the pipe to the Python until the C prog is done running, which certainly doesn’t qualify as a real time.

    Edit 2: Based on Richard’s link and some earlier thinking I had done, it occurred to me that it might be possible to manually loop over the pipe by treating it as a file object and only reading one line at a time:

    from time import sleep
    # Assume proc is the Popen object
    wait_time = 1 # 1 second, same delay as `tail -f`
    while True: # Or whatever condition you need
        line = proc.stdout.readline()
        if line != '' and line != '\n':
            parse_line_do_stuff()
    
        sleep(wait_time)
    

    This assumes that readline() is non-blocking, and further assumes that the pipe is at most line buffered, and even then it might not work. I’ve never tried it.

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

Sidebar

Related Questions

I have a multi-threaded program. I want to embed a python interpreter. I don't
I have a threaded program in Python that works fine except that __del__ does
Possible Duplicate: Is stl vector concurrent read thread-safe? I have a multi-threaded program that
When I run a single-threaded program that i have written on my quad core
I currently have a multi-threaded program that crawls websites and writes their text to
Possible Duplicate: Are C# arrays thread safe? I have a program that is single-threaded
I have a Python program that spawns many threads, runs 4 at a time,
I have a multi-threaded C++ program that deadlocks in some rare cases. The problem
I have a multi threaded application that writes to a settings xml file using
If I have a multi-threaded program that reads a cache-type memory by reference. Can

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.