
In the virt-manager app I'm using the python bindings to libvirt for all operations. For long running operations such as creating new domains, or saving/restoring domains I fork a background thread to do the call, so that the main UI / status refresh can carry on working. Except this wasn't working. The main thread was being blocked for the entire duration of the background thread. After a lot of nasty debug sessions I discovered that the main thread was being blocked in the GTK event loop attempting to aquire the Python GIL (Global Interpreter Lock). The only way this could be occurring is if the background thread doing the libvirt call held the GIL. And indeed after looking at the source for the libvirt python bindings it appears we never release the GIL when calling into the libvirt C apis, so for the entire duration of virDomainCreateLinux the python interpreter is completely stopped. Clearly this sucks because virDomainCreateLinux can take a very long time. I read up a little on python threading & looked at how PyGTK deals with this & have come up with a patch to make libvirt release the GIL when entering a C call & re-aquire it on completion. Indeed, since PyGTK & GTK are both LGPL, I just copied their C macros straight over. The patch appears to work - the python interpreter is no longer deadlocked when calling virDomainCreateLinux (or any other libvirt calls). Unfortuntely the virtmanager app still deadlocks, because it turns out XenD itself serializes all SEXPR HTTP requests, but once this is fixed the whole thing is fully parallelized & works without blocking the app. Attached the patch - I've not done much python threading before so let me know if i missed anything / messed stuff up. NB, I also hacked up the error handling callback so it re-acquires the lock before calling back into the python. Regards, Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|