有什么地方可以让我查看在 Python 的多处理环境中执行pySerial操作的示例?
===更新上述问题===
Arduino代码:
//Initialize the pins
void setup()
{
//Start serial communication
}
void loop()
{
//Keep polling to see if any input is present at the serial PORT
//If present perform the action specified.
//In my case : TURN ON the led or TURN OFF.
}
Python 前端的类似代码:
作为基本参考,我使用了 Painless Concurrency: The multiprocessing Module , (PDF, 3.0 MB)。
#import the different modules like time,multiprocessing
#Define the two parallel processes:
def f1(sequence):
#open the serial port and perform the task of controlling the led's
#As mentioned in the answer to the above question : Turn ON or OFF as required
#The 10 seconds ON, then the 10 seconds OFF,finally the 10 seconds ON.
def f2(sequence):
#Perform the task of turning the LED's off every 2 seconds as mentioned.
#To do this copy the present conditions of the led.
#Turn off the led.
#Turn it back to the saved condition.
def main():
print "Starting main program"
hilo1 = multiprocessing.Process(target=f1, args=(sequence))
hilo2 = multiprocessing.Process(target=f2, args=(sequence))
print "Launching threads"
hilo1.start()
hilo2.start()
hilo1.join()
hilo2.join()
print "Done"
if ____name____ == '____main____':
main()
在执行上述操作时,我面临一些问题:
进程 f1 根据需要执行任务。即点亮LED 10秒,熄灭LED 10秒,最后点亮LED 10秒。看起来,虽然程序成功结束,但进程 f2 似乎根本没有执行(即没有每两秒关闭一次 LED)。这里会发生什么?
如果我在进程中使用 print 打印某些内容,它不会出现在屏幕上。我很想知道提到这些示例的人如何能够显示流程打印的输出。