Python GUI开发:从基础到实践
1. Python处理进程与守护进程示例
在Python中处理进程时,我们能看到其成熟和强大之处。Python拥有优雅且复杂的线程API,但要时刻记住全局解释器锁(GIL)的存在。如果是I/O密集型任务,GIL通常不是问题;但如果需要多处理器并行处理,使用进程是不错的选择。甚至有人认为,即使没有GIL,使用进程也比使用线程更好,主要原因在于调试线程代码可能是一场噩梦。
以下是一个简单的守护进程编写示例:
No mod 5 at 1207272456.18 No mod 5 at 1207272457.19 No mod 5 at 1207272458.19 No mod 5 at 1207272459.19 No mod 5 at 1207272461.2 No mod 5 at 1207272462.2 No mod 5 at 1207272463.2 No mod 5 at 1207272464.2 No mod 5 at 1207272466.2 No mod 5 at 1207272467.2 No mod 5 at 1207272468.2 No mod 5 at 1207272469.2 No mod 5 at 1207272471.2 No mod 5 at 1207272472.2 jmjones@dinkgutsy:code$ cat /tmp/stderr.log Mod 5 at 1207272455.18 Mod 5 at 1207272460.2 Mod 5 at 1207272465.2 Mod 5 at 1207272470.2