Saturday, 30 June 2007

Python, os.fork() and GSoC

This one was a bit tricker to find, so I'm going to post it here: if you use os.fork() on Python, you will want to use os._exit() on the child process, or it will clean stuff it shouldn't and you will have segfaults with doubled memory free. That said, python's webbrowser module is quite useful; check it if you ever has to open a browser from a Python script/program. The only downside I see on it is exactly that it doesn't takes care of the forking stuff for you. I'm using it on bug-triage to show a bug report on the user browser. Talking about GSoC, during the last week the Debian BTS was updated, breaking, between other things, btsutils' 0.1 version. The current development version of btsutils, which uses BeautifulSoup to parse the HTML stuff more realiable, wasn't affected by the update. That's all for now, time to code.

1 comment:

Marius said...

Can you provide some code to demonstrate the fork/exit problem?

When you use os.fork(), you get two processes with their own memory areas. The child *cannot* make modifications to the parent's memory. Unless you used shared memory or some other form of interprocess communication. (I imagine file locks and sockets may cause problems if you're not careful.)