<p>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.</p>

CC BY-SA 3.0
2013-11-01T17:28:22.430Z
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
CC BY-SA 3.0
2013-11-01T03:30:48.890Z
2013-11-01T03:30:48.890Z
David Schwartz
<p>Rather than polling for transactions, you can use <code>pynode</code> or <code>bitcoin-sniffer</code> 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 <code>walletnotify</code> option set, which will execute your command with the details of the new transaction. </p>

CC BY-SA 3.0
2013-11-03T10:06:10.960Z
Very useful links. Seems to be a lot easier to use than polling. Many thanks!
Marco Polo
CC BY-SA 3.0
2013-11-02T23:07:20.343Z
2013-11-02T23:07:20.343Z
Anonymous
<p>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.</p>

<p>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).</p>

<p>When I searched for an answer I found:</p>

<p><a href="https://bitcoin.stackexchange.com/questions/12590/are-bitcoin-commands-resistant-to-race-conditions-and-thread-safe">Are bitcoin commands resistant to race conditions and thread-safe?</a></p>

<p>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).</p>

<p>Thanks.</p>

<bitcoind><json-rpc>
Is calling the bitcoind RPC multi-thread safe?
Marco Polo
# Is calling the bitcoind RPC multi-thread safe?

(Asked by: username_0 on 2013-10-31)

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?](https://bitcoin.stackexchange.com/questions/12590/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.

**Tags:** bitcoind, json-rpc


---

## 2 answers

### Answer by username_1 on 2013-11-01. Score: 3 | Accepted answer

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.

> **Comments:**
> **username_0**: 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.  

---

### Answer by username_2 on 2013-11-02. Score: 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.

> **Comments:**
> **username_0**: Very useful links. Seems to be a lot easier to use than polling. Many thanks!  

---

