Uncategorized

python parallel programming notes

Asked 
Viewed 5 times
1

I want to write a program which can operate 2 gpio pins with different ON OFF time at same time.

Say the time duration is 2 sec. In this time duration, I want to set GPIO 4 HIGH for 1 sec and LOW for 1 sec. And in that 2 sec same duration, I want to set GPIO 5 HIGH for 0.5 sec and LOW for 1.5 sec. I am not getting the logic how to do this.

  • Ah. you are asking a difficult question. The crux of the matter is that the “sleep” function is a “blocking” function, meaning that if say, you are executing two statements, first statement is “sleep(1)”, and the following statement is “sleep(2)”. Now when the python interpreter starts executing the first statement, it, I mean the lazy interpreter will actually sleeps for 1 second, before waking up to execute the following statement. / continue, ,,, – tlfong01 11 mins ago   
  • What you can can to execute two sequences of statement at the same time (“in parallel”, or “concurrently”) is to use the python module “multi-processing” (preferred) or “multi-threading” (not preferred). – tlfong01 10 mins ago   
  • If you wish to learn parallel or concurrent python programming, I would suggest to first read a tutorial about “multi-threading”, then move on to ‘multi-processing”. The reason that I say MP is preferred, and MT not preferred, but MT is the old thing which have been used for many many years. MP is new, sort of an improved version of MT, but unluckily many MP tutorials from time to time referred to the old MT. / to continue, … – tlfong01 2 mins ago   Edit   
  • In other words, you still need to know a little bit of MT (but don’t dig too deep) in order to thoroughly understand what the MP guys are talking. Just thinking aloud, sorry for the typos. Happy multi-processing. Cheers. – tlfong01 2 mins ago   Edit   
  • Ah, I forgot to ive your the important web link: (1) Python 3.8.1 Multiprocessing — Process-based parallelism docs.python.org/3/library/multiprocessing.html. – tlfong01 30 secs ago   Edit   

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: