3

My application uses bitcoind RPC with a Python wrapper. I want to write one thread that periodically watches a number of addresses by calling "listtransactions". Other threads might need to call other API commands in the meantime.

Is it safe to use bitcoind in such a multi-thread setup? (maybe I will use multi-processing in the end because of Pythons global interpreter lock).

When I searched for an answer I found:

Are bitcoin commands resistant to race conditions and thread-safe?

But I am not sure if this answer applies to my problem (and I am also not sure whether Pieter's "yes" is a reply to the first or the second question).

Thanks.

3

It can be done safely but it can also be done unsafely. If each thread uses its own connection, then it is safe. If the threads "fight" over the connections, then it won't work.

  • Thanks. That is very helpful. I will use then conn = bitcoinrpc.connect_to_local() in each thread, to ensure each thread uses its own connection. – Marco Polo Nov 1 '13 at 17:28
2

Rather than polling for transactions, you can use pynode or bitcoin-sniffer to connect to the node directly and parse transactions as they happen. If the addresses are in your wallet, you can call bitcoind with the walletnotify option set, which will execute your command with the details of the new transaction.

  • Very useful links. Seems to be a lot easier to use than polling. Many thanks! – Marco Polo Nov 3 '13 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.