Python Forum
Line by line execution of instructions - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Line by line execution of instructions (/thread-40397.html)



Line by line execution of instructions - JosephR - Jul-22-2023

Can I force a program to execute instructions in the order they are written, line by line


RE: Line by line execution of instructions - deanhystad - Jul-22-2023

What do you mean? What you describe is how programs run unless they contain functions or loops. Do you want the program to pause between instructions?


RE: Line by line execution of instructions - JosephR - Jul-24-2023

I am writing a program to run on a multi processor.. The ordering of. Of the statements is vitally important for the program to interact correctly with other programs. Is there a way to tell a Python compiler : do not change the order of instructions when compiling this program? Or maybe do not change the order of instructions starting at this point and ending at this other point when compiling this program. Handling loops ? inst1 Inst2 do n times inst3a inst3b end. inst4 inst5 Is executed as this sequence of instructions. inst1 inst2 inst3a inst3b ...... inst3a inst3b inst4 inst5 where the. inst3a inst3b Sequence is repeated n times


RE: Line by line execution of instructions - deanhystad - Jul-24-2023

The compiler does not change the order of instructions. "Compiling" in Python consists of converting the source code to bytecode that is run by the Python interpreter. There is no optimization stage that can change the order of the instructions. Loops remain loops. They are not flattened,

Python programs are single threaded unless they are explicitly written to be multi-threaded or use multiprocessing. You don't have to worry about the python interpreter taking your program and running it on multiple processors without your knowledge.

If you are doing multi-processing, there is no automatic mechanism for doing so. You have to write the code to create subprocesses. When using multiprocessing, there is no automatic method for synchronization. You have to write extra code to synchronize the processes. This can be fairly simple if you just need to wait for a subprocess to complete (start/join, await) but is more complicated when trying to synchronize two processes while running.

Could you provide more information about your particular concerns and what you are trying to do?