Keep a script running in the background

G

Guillermo

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
 
D

Daniel Fetchinson

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/Cookbook/Python/Recipe/278731
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012

Cheers,
Daniel
 
B

Bjoern Schliessmann

Guillermo said:
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
 
S

subeen

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/
 
G

Guillermo

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.
 
M

M.-A. Lemburg

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/python/mxBase/mxBeeBase/

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source (#1, Jun 04 2008)________________________________________________________________________
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
 

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,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top