Downloading 2 tables from db, does calculation and uploads resulting table
I know, that you know, that your code is messy, but I'm still going to give some tips on your coding style. Here are a few tips I have on what can be improved there.


Don't use % for string formatting, as it is deprecated. You should be using str.format() instead. Here's an example: print "Hello {0}".format("world")
You can remove the docstring at the end of your file containing """!@endcond""". This does nothing, and serves no purpose.
Separate this out into different functions. In it's current state, it's really hard to read as one large block of code.
Add more comments. Comments will make your code much clearer, and easier to read. Functions and classes should use docstrings, over regular inline comments.

Don't import multiple modules on one line. If an error occurs with one module, it can be hard to distinguish where the error came from.
Some variable names could be better. For example, the names sts, or shp2pgsql provide no useful information. Try to find any other names with not so great names, and see how you can improve them.
I'm not an expert on asynchronous programming, or any of the modules provided in Python made for this, but if you want to do a task like this, Python 3.5 will include the async and await keywords built for asynchronous programming. 


The official style guide for Python, PEP8, can be found here.