SwapOff

Python hacking, redux. 
Filed under

multicore

 

Python "multiprocessing" and sockets

It seems obvious in retrospect (doesn't it always), but using the multiprocessing module doesn't exempt you from the fundamental laws of UNIX. Laws such as "forks duplicate file descriptors". Consequently, when you launch a multiprocessing.Process() and pass it a socket, ensure that you close the socket in the parent. If you don't, it will stay open after the child has closed it, resulting in leaking badness.

Loading mentions Retweet
Filed under  //   multicore   network   processes   python  

Comments [0]

Multi-threading and PyGTK

The "easiest" way of integrating threads with PyGTK applications seems to be by using gobject.

Initialisation before starting the GTK main loop:

import gobject
gobject.threads_init()

Schedule any rendering functions from your thread with:

gobject.idle_add(window.queue_draw)

Also useful is the timeout_add function, which schedules periodic callbacks:

gobject.timeout_add(250, window.queue_draw)

Loading mentions Retweet
Filed under  //   gtk   multicore   python   threads  

Comments [6]