0

I have the following program running

collector.py

data=0
while True:
    #collects data
     data=data+1

I have another program cool.py which wants to access the current data value. How can I do this?

Ultimately, something like:

cool.py

getData() 

*An Idea would be to use a global variable for data?

High schooler
  • 1,682
  • 3
  • 30
  • 46
  • Do you want a daemon? http://stackoverflow.com/questions/473620/how-do-you-create-a-daemon-in-python – Rusty Rob Oct 25 '13 at 04:03
  • The simplest way is to write the data to a file every minute with a timestamp on the filename. Then your other file could just look for new files every minute & delete them once processed. – Rusty Rob Oct 25 '13 at 04:04
  • 2
    `global` won't help: each process has its own globals. You need some form of inter-process communication, and *both* programs have to *cooperate* to make this happen. Possibilities include sockets, pipes, the `multiprocessing` module, or something as simple as one program periodically writing data to a file and the the other program reading that file. – Tim Peters Oct 25 '13 at 04:04
  • I actually have a way of combining the programs – High schooler Oct 25 '13 at 04:13

1 Answers1

0

You can use memory mapping. http://docs.python.org/2/library/mmap.html

For example you open a file in tmp directore, next u mapping this file to memory in both program and write u data to this file.

Naster
  • 344
  • 1
  • 7