I have some dlls that control a hardware piece to acquire some information. They work by having a infinite loop that keeps doing constant acquisitions of new data every couple of seconds.
Is it possible to warp this infinite loop function so it can be called in python in parallel while other work is done (periodically checking the loop for new data)? Or would it be better to replicate the loop in python (I would need them to save all the current state of the C functions on each execution)?
In other words, I want to call this function and have it start acquiring and them every couple of seconds peak at the data (from python) to see it.
Bellow a minimal example
On C:
#include <stdio.h>
void loop()
{
while( 1 )
{
GetNewData();
sleep(1);
}
}
On python:
import multiprocessing as mp
from multiprocessing.pool import Pool
from ctypes import *
def worker():
lib = CDLL("test.dll")
lib.loop()
def call(func):
global p
a = p.apply_async(func)
a.get()
if __name__ == '__main__':
p = Pool(1)
call(worker)
DoSomethingElse() # Code never reaches this point.