1

I am running below program at same time on two command line console,

import time
var = 10
print("Variable is::-",id(var))
time.sleep(10)
var=var+1
print("Variable is::-",id(var))


console 1 output: 
C:\Users\My Laptop>python d:\p1.py
Variable is::- 1796725056
Variable is::- 1796725072

console 2 output:
C:\Users\My Laptop>python d:\p1.py
Variable is::- 1796725056
Variable is::- 1796725072

how can different console session share same memory location for variable

  • 1
    Why can't they? They're run sequentially, not parallelly, so the memory of the first run has already been freed up for the second run to be allocated the same. – blhsing Dec 15 '18 at 03:33
  • 1
    @blhsing OP explicitly said "run in parallel" - also it does not really have any impact on per-process address space. Some reading about [virtual memory](https://stackoverflow.com/questions/510544/virtual-memory) may help OP to figure out what they have concerns about. – Alexei Levenkov Dec 15 '18 at 03:48
  • @blhsing Even though they are running sequentially, first program is still running(due to sleep) when second one is started. So how come they share same memory space. – patilsanketv Dec 22 '18 at 04:25

0 Answers0