From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.3d73Ybk3C5U4I2t8lv+lAQ.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Running a simple Python from Ada program Date: Fri, 3 Apr 2020 22:06:49 +0200 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: 3d73Ybk3C5U4I2t8lv+lAQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:58303 Date: 2020-04-03T22:06:49+02:00 List-Id: On 2020-04-03 21:19, Rego, P. wrote: >>> Do not do that. There exist Python C API, which you should use: >>> https://docs.python.org/3/c-api/index.html >> You mean that the problem is with the Python "print" ? > > I tested with a very simple C code. If the Python print is blocked, it should be blocked also from a C call, I presume (ok someone will contest, anyway). Any case, from the C call, it does not block. > > So I will try to simplify a bit the question. I want to do the equivalent of this > > #include > #include > int main(){ > system("python testpy.py ddddd"); > return 0; > } > In this case it does not block the testpy.py printouts. > > But I am doing this > with Interfaces.C; use Interfaces.C; > procedure systest2 is > function Sys (Arg : Char_Array) return Integer; > pragma Import(C, Sys, "system"); > Ret_Val : Integer; > begin > Ret_Val := Sys(To_C("python testpy.py arg1 arg2")); > end systest2; > which blocks the testpy.py script until its end. This should not happen. It must, actually: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/system-wsystem?view=vs-2019 > So, please, how could I fix this? You need spawn python in an asynchronous process or else a batch script with something like "call python test.py ddddd" inside. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de