1
I was looking at ../qa/rpc-tests/util.py in order to figure out how arbitrary ports are assigned to each created node.
In the first lines of the code it says:
...
def p2p_port(n):
return 11000 + n + os.getpid()%999
...
So I'm wondering what exactly os.getpid()%999 does? Is it instantly looking for a free port?
Thanks in advance!
Ok, but what I don't understand is how a pid can be set inside a configuration file for a process that is non-existent yet? Can you follow my thought? :/ – Aliakbar Ahmadi – 2015-04-15T15:57:48.150
1The pid that
os.getpid()returns is the pid of the Python script at the time that it is being run. Wheneverp2p_port(n)is called, the id of the process that is currently running is returned. Is that more clear? – JohnDvorak – 2015-04-15T16:01:42.490Yes a little bit, since I'm a newbie in this field. So you say everytime this python script is run, it starts many process instances (nodes) of the python programm (not bitcoind!) that have individual process ids? – Aliakbar Ahmadi – 2015-04-15T16:05:50.673
1Looking at the code now, it seems like
util.pyjust includes functions that are used by other portions of the test code. So every time other portions of the code callinitialize_datadir()andinitialize_chain()(which then callp2p_port()), the pids will be the same if they are called within the same process. – JohnDvorak – 2015-04-15T16:14:43.473Exactly initialize_datadir() is the point of confusion. My understanding/pattern of creating a network of peers is the following: – Aliakbar Ahmadi – 2015-04-15T21:40:03.853
Step 1) create config file with free port and rpc port – Aliakbar Ahmadi – 2015-04-15T21:40:37.053
Step 2) run bitcoind instance separately by specifying independent config files - running bitcoin instantly gets a process id – Aliakbar Ahmadi – 2015-04-15T21:41:43.073
BUT in the util.py code it seems to me that step1 and 2 are twisted since for writing a config file a pid for the port no. Structure is needed – Aliakbar Ahmadi – 2015-04-15T21:43:23.827
1I think the source of confusion is that os.getpid() is not the process id of bitcoind, but of the Python script. It has nothing to do with the bitcoind pid, and is only a way to make the port different between tests. – JohnDvorak – 2015-04-15T22:36:01.847
Ok. Thanks a lot I did a bit of research basing on your hints so it's much clearer now! – Aliakbar Ahmadi – 2015-04-16T19:47:51.787
1Glad I helped! :) – JohnDvorak – 2015-04-16T19:49:02.047