BitcoinEmulator¶
-
class
privex.rpcemulator.bitcoin.
BitcoinEmulator
(host='', port: int = 8332, background=True)[source]¶ Process manager class for the
bitcoind
emulator web server.Without any constructor arguments, will fork into background at http://127.0.0.1:8332
By default,
background
is set to True, meaning it will launch as a sub-process, instead of blocking your application.Using with a Context Manager:
By using
BitcoinEmulator
as a context manager, the JsonRPC server will be started before the first line inside of thewith
statement, and will automatically shutdown at the end of thewith
statement.>>> from privex.rpcemulator.bitcoin import BitcoinEmulator >>> >>> with BitcoinEmulator(): ... # make some queries to the RPC at https://127.0.0.1:8332 ... >>> # Once the `with` statement is over, the JsonRPC server automatically shuts down
Alternative
You can create an instance of BitcoinEmulator normally, but you should make sure to call
terminate()
when you’re done with using the emulator.This may be preferable when using inside of a unit test which has a setUpClass and tearDownClass method:
>>> from privex.rpcemulator.bitcoin import BitcoinEmulator >>> btc_rpc = BitcoinEmulator() >>> # make some queries to the RPC at https://127.0.0.1:8332 >>> # once you're done, terminate the process >>> btc_rpc.terminate()
Methods¶
Methods
|
Without any constructor arguments, will fork into background at http://127.0.0.1:8332 |
Called when a user wants to manually terminate the background process. |