I am writing a code in python on a raspberry pi
while(true):
functionA
functionB
Function A is basically a command that captures images in png format. I do not want it be a blocking function. I want my code to proceed to function B, while in the mean time function A captures the image and makes the data ready for the next run.
I am confused on whether to use a thread or a process.
If I have to use a thread, when will it stop? Will it stop once after function A completes it's execution? And in that case, I need to call start method every time I have to start this thread? Or should I use a process and how will I go about it meaning when will a process stop.
Let's be clear about the differences between a thread and a process. An informal definition: A thread is a sequence of code that executes as part of a process; A process may contain many threads which all share the same process space and virtual memory space. Threads will end (and terminate themselves) upon completion without necessarily ending the parent process. From what it sounds like, you should use a thread for executing functionA synchronously. A new process will definitely take more resources and sounds unnecessary. Also, yes you will need to create the thread again if you need that code to execute again after the thread has fully finished execution. On the other hand, you could write the code that executes within the new thread in a manner that loops indefinitely, if that approach seems appropriate for the task you are performing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With