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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:49:16+00:00 2026-05-20T00:49:16+00:00

I have a Python script and a C program and I need to pass

  • 0

I have a Python script and a C program and I need to pass large quantities of data from Python script that call many times the C program. Right now I let the user choose between passing them with an ASCII file or a binary file, but both are quite slow and useless (I mean files are useful if you want to store the data, but I delete these files at the end of the script).

os.system doesn’t work, the arguments are too much as the C program too uses files to return data to Python, but this is much less data.

I wonder what I can use to make this exchange fast. Writing the files to a RAM disk? If so, how can I do this?

I heard is possible to call functions from DLL using ctypes, but don’t know how to compile my program as a DLL (I use wxdevc+ on Windows 7 64).
Or wrap it, but still don’t know if it can work and if it is efficient.

The data are vertices of a 3D mesh.

I’m running the Python script inside another program (blender (open source), and is called many times (usually more than 500 times) because it’s inside a cycle. The script send vertices information (1 int index and 3 float coords) to the program, and the program should return many vertices (only int index, because I can find the corresponding vertices with Python).

So this is not interactive, it’s more like a function (but it’s wrote in C). The script + C program (that are add-ons of blender) that I’m writing should be cross-platform because it will be redistributed.

The program is actually wrote in C, and from Python I can know the address in memory of the struct that contains the vertices data. If only I know how to do this, should be better to pass to the C program only an address, and from there find all the other vertices (are stored in list).

But as far as I know, I can’t access to the memory space of another program, and I don’t know if calling the program with pipes or whatever initialize a new thread or is run inside the script (that is actually run under the Blender thread)

Here is the source and blender/source/blender/makesdna/DNA_meshdata_types.h should be the struct definition

  • 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-05-20T00:49:17+00:00Added an answer on May 20, 2026 at 12:49 am

    Pipes are the obvious way to go; if your c program accepts input from stdin, you can use Popen. This doesn’t create a “thread” as you say in your edit; it creates an entirely new process with separate memory:

    from subprocess import Popen, PIPE
    
    input = "some input"
    cproc = Popen("c_prog", stdin=PIPE, stdout=PIPE)
    out, err = cproc.communicate(input)
    

    Here’s a more detailed example. First, a simple c program that echoes stdin:

    #include<stdio.h>
    #include<stdlib.h>
    #define BUFMAX 100
    
    int main() {
        char buffer[BUFMAX + 1];
        char *bp = buffer;
        int c;
        FILE *in;
        while (EOF != (c = fgetc(stdin)) && (bp - buffer) < BUFMAX) {
            *bp++ = c;
        }
        *bp = 0;    // Null-terminate the string
        printf("%s", buffer);
    }
    

    Then a python program that pipes input (from argv in this case) to the above:

    from subprocess import Popen, PIPE
    from sys import argv
    
    input = ' '.join(argv[1:])
    if not input: input = "no arguments given"
    cproc = Popen("./c_prog", stdin=PIPE, stdout=PIPE)
    out, err = cproc.communicate(input)
    print "output:", out
    print "errors:", err
    

    If you don’t plan to use the c program without the python frontend, though, you might be better off inlining a c function, perhaps using instant.

    from instant import inline
    c_code = """
        [ ... some c code ... ] //see the below page for a more complete example.
    """
    c_func = inline(c_code)
    

    As Joe points out, you could also write a python module in c: Extending Python with C or C++

    This answer discusses other ways to combine c and python: How do I connect a Python and a C program?

    EDIT: Based on your edit, it sounds like you really should create a cpython extension. If you want some example code, let me know; but a full explanation would make for a unreasonably long answer. See the link above (Extending Python…) for everything you need to know.

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

Sidebar

Related Questions

I have a Python script that calls an executable program with various arguments (in
I have a Python script that needs to execute an external program, but for
I have a Python script I recently wrote that I call using the command
I have a python script that, once executed from command line, performs the needed
I have a Python script that writes data packets to an Arduino board through
Is there a way to call a program (Python script) from a local HTML
I have a Python CGI script from which I am trying to call a
I've wrote a python script that need to pass millions of items to a
I have a python script that analyzes a set of error messages and checks
I have a python script that is a http-server: http://paste2.org/p/89701 , when benchmarking it

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.