share dictionary between processes

B

blumenkraft

Hi,

I want to share dictionary between two distinct processes.


Something like this:

first.py
import magic_share_module

def create_dictionary():
return {"a": 1}

magic_share_module.share("shared_dictionary",
creator.create_dictionary)
while True:
pass


second.py
import magic_share_module
d = magic_share_module.get_shared("shared_dictionary")
print d["a"]

And then run in command line:
python first.py &
sleep 1
python second.py

I have looked at POSH, but it requires master process that will fork
childs. I want read-only sharing between completely unrelated
processes.
Is it possible?
 
G

garabik-news-2005-05

blumenkraft said:
Hi,

I want to share dictionary between two distinct processes.
....
I have looked at POSH, but it requires master process that will fork
childs. I want read-only sharing between completely unrelated
processes.
Is it possible?

Depends on your exact needs - dbm or shelve might be enough, especially for
read only access.

--
-----------------------------------------------------------
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk |
-----------------------------------------------------------
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
 
M

Michele Simionato

Hi,

I want to share dictionary between two distinct processes.

Something like this:

first.py
import magic_share_module

def create_dictionary():
    return {"a": 1}

magic_share_module.share("shared_dictionary",
creator.create_dictionary)
while True:
     pass

second.py
import magic_share_module
d = magic_share_module.get_shared("shared_dictionary")
print d["a"]

And then run in command line:
python first.py &
sleep 1
python second.py

I have looked at POSH, but it requires master process that will fork
childs. I want read-only sharing between completely unrelated
processes.
Is it possible?

Yes, see http://docs.python.org/library/multiprocessing.html
 
N

News123

Hi Michael,

I'm new to the module multiprocessing, but at a first glance
it seems, that multiprocessing.Value can only be shared if
you create the second process from the first one.

Id like to start the first process from the command line and much later
the second process from the command line.

Is this possible?


thanks in advance and bye




N




Michele said:
Hi,

I want to share dictionary between two distinct processes.

Something like this:

first.py
import magic_share_module

def create_dictionary():
return {"a": 1}

magic_share_module.share("shared_dictionary",
creator.create_dictionary)
while True:
pass

second.py
import magic_share_module
d = magic_share_module.get_shared("shared_dictionary")
print d["a"]

And then run in command line:
python first.py &
sleep 1
python second.py

I have looked at POSH, but it requires master process that will fork
childs. I want read-only sharing between completely unrelated
processes.
Is it possible?

Yes, see http://docs.python.org/library/multiprocessing.html
 
R

r0g

blumenkraft said:
Hi,

I want to share dictionary between two distinct processes.


Something like this:

first.py
import magic_share_module

def create_dictionary():
return {"a": 1}

magic_share_module.share("shared_dictionary",
creator.create_dictionary)
while True:
pass


second.py
import magic_share_module
d = magic_share_module.get_shared("shared_dictionary")
print d["a"]

And then run in command line:
python first.py &
sleep 1
python second.py

I have looked at POSH, but it requires master process that will fork
childs. I want read-only sharing between completely unrelated
processes.
Is it possible?



Depends if you need to have access to the object itself or merely look
up values in it. If it's the latter you could start a thread in first.py
that offers dictionary lookups via a specific UDP socket. Any number of
subsequent progs and processes could then pitch up and lookup whatever
values they like whenever they like. ~10 lines of code in first.py,
maybe 5 in second.py

Roger.
 
W

Wolodja Wentland

I want to share dictionary between two distinct processes.
Something like this:

first.py
import magic_share_module
def create_dictionary():
return {"a": 1}

magic_share_module.share("shared_dictionary",
creator.create_dictionary)
while True:
pass

Have a look at multiprocessing.Manager() it provides (among other
things) proxies for dictionaries that can be used in different threads.
These are even accessible on different hosts if configures correctly.
--
.''`. Wolodja Wentland <[email protected]>
: :' :
`. `'` 4096R/CAF14EFC
`- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQIcBAEBCAAGBQJLK4+6AAoJEIt/fTDK8U78Zq0P/25SC4TFoNJF6dH9KpIpYjwJ
5Eb0f5sNmqyV8Q1Zs0RYuFTVapPKgDh1IyJXSI4I/LHAwRvnc9zERmixrj60aE5k
kxMnd1hb1dtVKf4smUd6Ss1Id5fAqIO9PiCsFANDkSLhd5ZqfDh9N+CtbpLB+S3a
oPJD3wSKvHK5b3aq2cHvlGeFGfbC+TTcEQZHPgPhn2sjZKrIMVIDuDQX5xPeqLj8
4kTH7+CeqkyLxH8ZO9MsoMVlQgoQLi734chTbyoHV7SJcRdVtrm64ewyv9qHjH/U
0+OwrXCXcuzbV/ebAqF2G6A6eh2gHh4Zgi2PqB08oti4mGWV/E9RQ6E7CpWKyDQP
mFJtUzlHYjwXaaUDQY6IOD5LTvJavr+f85toT3aLTelJxKUejzMSsr3i+V2HIuLb
GBLKezCdR+9bU03RKIWko8htBba8WkFbzGMtrXyfScsN18w9GV5SvAQ68JEa7l6Y
tnr53FtP28P9xv41w95mTBjSst/tFSLl41WNPmBqTbGvzsdxTQV78pmIU8o86bJ2
mv6LSbDagpgcKpfASZJwfOff+L2Q51l4Q579vB/+bqnqvSpNI1s16+TIt0qI2zJD
arKE0H8yIw0JQoKotjB5NOIRgzAXzI/7KjkvhNTD/zR6O3Bp9wxk2vWkuAaC3MrG
6pKaAlo2/NIkAOC/EC7p
=HBj7
-----END PGP SIGNATURE-----
 
S

Steve Holden

blumenkraft said:
Hi,

I want to share dictionary between two distinct processes.


Something like this:

first.py
import magic_share_module

def create_dictionary():
return {"a": 1}

magic_share_module.share("shared_dictionary",
creator.create_dictionary)
while True:
pass


second.py
import magic_share_module
d = magic_share_module.get_shared("shared_dictionary")
print d["a"]

And then run in command line:
python first.py &
sleep 1
python second.py

I have looked at POSH, but it requires master process that will fork
childs. I want read-only sharing between completely unrelated
processes.
Is it possible?

Take a look at pyro, though it may be overkill for your needs.

regards
Steve
 
S

Steve Holden

blumenkraft said:
Hi,

I want to share dictionary between two distinct processes.


Something like this:

first.py
import magic_share_module

def create_dictionary():
return {"a": 1}

magic_share_module.share("shared_dictionary",
creator.create_dictionary)
while True:
pass


second.py
import magic_share_module
d = magic_share_module.get_shared("shared_dictionary")
print d["a"]

And then run in command line:
python first.py &
sleep 1
python second.py

I have looked at POSH, but it requires master process that will fork
childs. I want read-only sharing between completely unrelated
processes.
Is it possible?

Take a look at pyro, though it may be overkill for your needs.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top