I am trying to have two things execute at the same time. I have some code to run a PWM module, and I have some code to read from an ADC and both work. I want to now read from the ADC while waiting for the pwm module to finish. I thought of forking, but wasn't sure how to get the parent to wait for the child to finish.
I'd like to have something like the following:
pid = os.fork()
if(pid > 0):
while(child not done):
adc code
else:
pwm code
Using multiprocessing I was able to do it.
pwm_p = Process(target=my_pwm, args=(my_args,))
pmw_p.start()
while(pwm_p.is_alive()):
read_from_adc()
You can use os.wait()
from the parent process to wait for the child to terminate. You can find an example of this here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.