Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > share dictionary between processes

Reply
Thread Tools

share dictionary between processes

 
 
blumenkraft
Guest
Posts: n/a
 
      12-18-2009
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?
 
Reply With Quote
 
 
 
 
garabik-news-2005-05@kassiopeia.juls.savba.sk
Guest
Posts: n/a
 
      12-18-2009
blumenkraft <(E-Mail Removed)> wrote:
> 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!
 
Reply With Quote
 
 
 
 
Michele Simionato
Guest
Posts: n/a
 
      12-18-2009
On Dec 18, 8:48*am, blumenkraft <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
News123
Guest
Posts: n/a
 
      12-18-2009
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 Simionato wrote:
> On Dec 18, 8:48 am, blumenkraft <(E-Mail Removed)> wrote:
>> 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

 
Reply With Quote
 
r0g
Guest
Posts: n/a
 
      12-18-2009
blumenkraft wrote:
> 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.
 
Reply With Quote
 
Wolodja Wentland
Guest
Posts: n/a
 
      12-18-2009
On Thu, Dec 17, 2009 at 23:48 -0800, blumenkraft wrote:
> 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 <(E-Mail Removed)-heidelberg.de>
: :' :
`. `'` 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
kxMnd1hb1dtVKf4smUd6Ss1Id5fAqIO9PiCsFANDkSLhd5ZqfD h9N+CtbpLB+S3a
oPJD3wSKvHK5b3aq2cHvlGeFGfbC+TTcEQZHPgPhn2sjZKrIMV IDuDQX5xPeqLj8
4kTH7+CeqkyLxH8ZO9MsoMVlQgoQLi734chTbyoHV7SJcRdVtr m64ewyv9qHjH/U
0+OwrXCXcuzbV/ebAqF2G6A6eh2gHh4Zgi2PqB08oti4mGWV/E9RQ6E7CpWKyDQP
mFJtUzlHYjwXaaUDQY6IOD5LTvJavr+f85toT3aLTelJxKUejz MSsr3i+V2HIuLb
GBLKezCdR+9bU03RKIWko8htBba8WkFbzGMtrXyfScsN18w9GV 5SvAQ68JEa7l6Y
tnr53FtP28P9xv41w95mTBjSst/tFSLl41WNPmBqTbGvzsdxTQV78pmIU8o86bJ2
mv6LSbDagpgcKpfASZJwfOff+L2Q51l4Q579vB/+bqnqvSpNI1s16+TIt0qI2zJD
arKE0H8yIw0JQoKotjB5NOIRgzAXzI/7KjkvhNTD/zR6O3Bp9wxk2vWkuAaC3MrG
6pKaAlo2/NIkAOC/EC7p
=HBj7
-----END PGP SIGNATURE-----

 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      12-18-2009
blumenkraft wrote:
> 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
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/
 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      12-18-2009
blumenkraft wrote:
> 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
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
Controlling processes and what to "feed" other processes Marc Heiler Ruby 1 05-24-2009 05:37 PM
Share objects between processes - how? patrik.xx.hoiem-flyckt@ericsson.com Perl Misc 3 04-20-2007 11:56 AM
share function argument between subsequent calls but not between class instances! K. Jansma Python 7 02-21-2006 01:31 PM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments