By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

Keep a script running in the background

P: n/a

Hi,

I need a script to keep running in the background after it's loaded
some data. It will make this data available to the main program in the
form of a dictionary, but I don't want to reload the calculated data
every time the user needs it via the main program.

I won't be working with an UI, hope that can be made easily in Python
somehow.

Cheers,

Guillermo
Jun 27 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
I need a script to keep running in the background after it's loaded
some data. It will make this data available to the main program in the
form of a dictionary, but I don't want to reload the calculated data
every time the user needs it via the main program.

I won't be working with an UI, hope that can be made easily in Python
somehow.
I'm not sure I understand exactly what you want but you might find
these daemonize examples useful from the cookbook:

http://aspn.activestate.com/ASPN/Coo.../Recipe/278731
http://aspn.activestate.com/ASPN/Coo...n/Recipe/66012

Cheers,
Daniel
--
Psss, psss, put it down! - http://www.cafepress.com/putitdown
Jun 27 '08 #2

P: n/a
Guillermo wrote:
I need a script to keep running in the background after it's
loaded some data. It will make this data available to the main
program in the form of a dictionary, but I don't want to reload
the calculated data every time the user needs it via the main
program.

I won't be working with an UI, hope that can be made easily in
Python somehow.
Sure. Try the subprocess module.

Regards,
Björn

--
BOFH excuse #205:

Quantum dynamics are affecting the transistors

Jun 27 '08 #3

P: n/a
On Jun 3, 10:07 pm, Guillermo <guillermo.lis...@googlemail.comwrote:
Hi,

I need a script to keep running in the background after it's loaded
some data. It will make this data available to the main program in the
form of a dictionary, but I don't want to reload the calculated data
every time the user needs it via the main program.

I won't be working with an UI, hope that can be made easily in Python
somehow.

Cheers,

Guillermo
You can try this command: nohup python script.py &

regards,
Subeen.
http://love-python.blogspot.com/
Jun 27 '08 #4

P: n/a
I need a script to keep running in the background after it's loaded
some data. It will make this data available to the main program in the
form of a dictionary, but I don't want to reload the calculated data
every time the user needs it via the main program.
If it were me, I'd go with a database server like mysql.
** Posted from http://www.teranews.com **
Jun 27 '08 #5

P: n/a

These are the basic requirements:

Script A must keep a dictionary in memory constantly and script B must
be able to access and update this dictionary at any time. Script B
will start and end several times, but script A would ideally keep
running until it's explicitly shut down.

I have the feeling the way to do this is Python is by pickling the
dict, but I need the method that gives the best performance. That's
why I'd rather want to keep it in memory, since I understand pickling
involves reading from and writing to disk.

I'm using SQLite as a database. But this dict is an especial index
that must be accessed at the highest speed possible.
Jun 27 '08 #6

P: n/a
On 2008-06-04 01:33, Guillermo wrote:
These are the basic requirements:

Script A must keep a dictionary in memory constantly and script B must
be able to access and update this dictionary at any time. Script B
will start and end several times, but script A would ideally keep
running until it's explicitly shut down.

I have the feeling the way to do this is Python is by pickling the
dict, but I need the method that gives the best performance. That's
why I'd rather want to keep it in memory, since I understand pickling
involves reading from and writing to disk.

I'm using SQLite as a database. But this dict is an especial index
that must be accessed at the highest speed possible.
If you're on Unix, it's easiest to have script A implement a
signal handler. Whenever it receives a signal, it rereads the
pickled dict from the disk. Script B then writes a new revision
of the dict and sends the signal to script A.

Alternatively, you could use an on-disk dictionary like e.g.
mxBeeBase:

https://www.egenix.com/products/pyth...ase/mxBeeBase/

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source (#1, Jun 04 2008)
>>Python/Zope Consulting and Support ... http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
__________________________________________________ ______________________
2008-07-07: EuroPython 2008, Vilnius, Lithuania 32 days to go

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.