How to code such that the program does not wait for execution of a command?

Rachit Semalty
Rachit Semalty Altair Community Member
edited September 2022 in Community Q&A

Hi. I am trying a code:

      exec python_path python_file.py;

      puts 1;

So the problem is that 1 is not printed till the execution of the python file is completed. I want the code to proceed even if the python file is still running.

Does anyone know how to solve the problem?

Regards,

Rachit

Best Answer

  • Ben Buchanan
    Ben Buchanan
    Altair Employee
    edited September 2022 Answer ✓

    I think what you are looking for is just to add an & to the end. Like this:

    exec python_path python_file.py &;

Answers

  • Nagahashi Kouta
    Nagahashi Kouta Altair Community Member
    edited September 2022

    Hi, Rachit Semalty

    The following commands may help you

    package require Thread
    set thread_id [thread::create {exec python_path python_file.py}]

    puts 1

  • Ben Buchanan
    Ben Buchanan
    Altair Employee
    edited September 2022 Answer ✓

    I think what you are looking for is just to add an & to the end. Like this:

    exec python_path python_file.py &;

  • Rachit Semalty
    Rachit Semalty Altair Community Member
    edited September 2022

    Hi, Rachit Semalty

    The following commands may help you

    package require Thread
    set thread_id [thread::create {exec python_path python_file.py}]

    puts 1

    Thanks, Nagahashi for your reply. It was helpful. I was hoping to do it without creating a thread but it is also a good solution.

     

    Regards,

    Rachit

  • Rachit Semalty
    Rachit Semalty Altair Community Member
    edited September 2022

    I think what you are looking for is just to add an & to the end. Like this:

    exec python_path python_file.py &;

    Hi Ben. Thanks for your reply. Your solution worked for me.

     

    Regards,

    Rachit