multiprocessing - How to increases the CPU usage of my Python program? -
i writing program in raspberry pi 3 read inputs using mcp3008 adc function generator. want read 2 channels @ same time , write file. when have 1 channel, 12000 samples per second, however, when have 2 channels, 6000 samples per second each channel. 12000 samples per second each channels, tried write 2 different scripts, 1 each channel , run them simultaneously in 2 different terminals. however, not solve problem , gives me 6000 samples per second each channel.
when have 1 script, 9% cpu usage. when run 2 scripts @ same time in 2 different terminals, 5% cpu usage each process. how each process use 9% cpu each or higher?
thank you!
here code:
import spidev, time, os # opens spi bus spi = spidev.spidev() spi.open(0, 0) #spi1 = spidev.spidev() #spi1.open(0, 1) ch0 = 0 #ch1 = 1 = time.time() * 1000 data = open("test_plot.dat", "w") #data1 = open("test_plot_1.dat", "w") def getreading(channel): # pull raw data chip rawdata = spi.xfer([1, (8 + channel) << 4, 0]) # process raw data understand processeddata = ((rawdata[1]&3) << 8) + rawdata[2] return processeddata """ def getreading1(channel): # pull raw data chip rawdata = spi1.xfer([1, (8 + channel) << 4, 0]) # process raw data understand processeddata = ((rawdata[1]&3) << 8) + rawdata[2] return processeddata """ while true: if (((time.time() * 1000) - now) < 10001): data.write("%d\n" % getreading(ch0)) #data1.write("%d\n" % getreading1(ch1)) else: break # http://www.takaitra.com/posts/492
Comments
Post a Comment