Keep a script running in the background

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guillermo

    Keep a script running in the background


    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
  • Daniel Fetchinson

    #2
    Re: Keep a script running in the background

    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:




    Cheers,
    Daniel
    --
    Psss, psss, put it down! - http://www.cafepress.com/putitdown

    Comment

    • Bjoern Schliessmann

      #3
      Re: Keep a script running in the background

      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

      Comment

      • subeen

        #4
        Re: Keep a script running in the background

        On Jun 3, 10:07 pm, Guillermo <guillermo.lis. ..@googlemail.c omwrote:
        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.

        Comment

        • Tobiah

          #5
          Re: Keep a script running in the background

          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 **

          Comment

          • Guillermo

            #6
            Re: Keep a script running in the background


            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.

            Comment

            • M.-A. Lemburg

              #7
              Re: Keep a script running in the background

              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:

              Build your own custom B+Tree based on-disk dictionaries, lookup tables and indexes in Python.


              --
              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.D atabase.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,S olaris,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

              Comment

              Working...