How to prevent from race conditions to share data between many process and thread in python

Discussion in 'Python' started by mars, Feb 6, 2007.

  1. mars

    mars Guest

    I use TurboGears to do some web service. TurboGears use cherrypy. When
    web browser access this site, the cherrypy will call my python
    program. So my program looks like a lib. When web browser access the
    site, the http server will fock a process or gerenate a thread. I need
    share some data or operate some files. How can I prevent from race
    conditions. Is there any way can I lock this.
    Thank you in advance!
     
    mars, Feb 6, 2007
    #1
    1. Advertising

  2. mars wrote:

    > I use TurboGears to do some web service. TurboGears use cherrypy. When
    > web browser access this site, the cherrypy will call my python
    > program. So my program looks like a lib. When web browser access the
    > site, the http server will fock a process or gerenate a thread. I need
    > share some data or operate some files. How can I prevent from race
    > conditions. Is there any way can I lock this.
    > Thank you in advance!


    There are the Lock and RLock objects available in the module threading.

    Diez
     
    Diez B. Roggisch, Feb 6, 2007
    #2
    1. Advertising

  3. mars

    mars Guest

    On 2ÔÂ6ÈÕ, ÏÂÎç6ʱ14·Ö, "Diez B. Roggisch" <> wrote:
    > mars wrote:
    > > I use TurboGears to do some web service. TurboGears use cherrypy. When
    > > web browser access this site, the cherrypy will call my python
    > > program. So my program looks like a lib. When web browser access the
    > > site, the http server will fock a process or gerenate a thread. I need
    > > share some data or operate some files. How can I prevent from race
    > > conditions. Is there any way can I lock this.
    > > Thank you in advance!

    >
    > There are the Lock and RLock objects available in the module threading.
    >
    > Diez


    Can this also lock mutil-process?
     
    mars, Feb 6, 2007
    #3
  4. mars wrote:

    > On 2月6æ—¥, 下åˆ6æ—¶14分, "Diez B. Roggisch" <> wrote:
    >> mars wrote:
    >> > I use TurboGears to do some web service. TurboGears use cherrypy. When
    >> > web browser access this site, the cherrypy will call my python
    >> > program. So my program looks like a lib. When web browser access the
    >> > site, the http server will fock a process or gerenate a thread. I need
    >> > share some data or operate some files. How can I prevent from race
    >> > conditions. Is there any way can I lock this.
    >> > Thank you in advance!

    >>
    >> There are the Lock and RLock objects available in the module threading.
    >>
    >> Diez

    >
    > Can this also lock mutil-process?


    No.

    Diez
     
    Diez B. Roggisch, Feb 6, 2007
    #4
  5. Re: How to prevent from race conditions to share data between manyprocess and thread in python

    En Tue, 06 Feb 2007 08:49:51 -0300, Diez B. Roggisch <>
    escribió:

    > mars wrote:
    >
    >> On 2月6æ—¥, 下åˆ6æ—¶14分, "Diez B. Roggisch" <> wrote:
    >>> mars wrote:
    >>> > I use TurboGears to do some web service. TurboGears use cherrypy.
    >>> When
    >>> > web browser access this site, the cherrypy will call my python
    >>> > program. So my program looks like a lib. When web browser access the
    >>> > site, the http server will fock a process or gerenate a thread. I
    >>> need
    >>> > share some data or operate some files. How can I prevent from race
    >>> > conditions. Is there any way can I lock this.
    >>> > Thank you in advance!
    >>>
    >>> There are the Lock and RLock objects available in the module threading.

    >>
    >> Can this also lock mutil-process?

    >
    > No.


    You have to use the syncronization tools provided by your OS in that case;
    maybe using a locked file (fcntl).

    --
    Gabriel Genellina
     
    Gabriel Genellina, Feb 6, 2007
    #5
  6. On 6 Feb 2007 01:51:40 -0800, "mars" <> declaimed the
    following in comp.lang.python:

    > I use TurboGears to do some web service. TurboGears use cherrypy. When
    > web browser access this site, the cherrypy will call my python
    > program. So my program looks like a lib. When web browser access the
    > site, the http server will fock a process or gerenate a thread. I need
    > share some data or operate some files. How can I prevent from race
    > conditions. Is there any way can I lock this.
    > Thank you in advance!


    Since you don't expand upon the type of data you need to "share", it
    is a touch difficult to respond. However, assuming you can not isolate
    the data/files by some session key/cookie ID, the next route is probably
    to place that data into something designed for concurrent access --
    meaning: use some RDBM system and let IT handle concurrent access (of
    course, you will have to code your procedures to handle RDBM status
    codes indicating updates by another client). Or, though it is likely the
    most complicated to implement, you have a long-running/persistent
    process acting as a server -- all accesses to shared data would be
    handled by sending requests/commands to this server process; since it
    only handles one request at a time, you can avoid "unseen" updates to
    the data [you may still have the problem of losing an update if two
    instances both send "set x to y" commands -- this is what the RDBM would
    catch and report].
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Feb 6, 2007
    #6
  7. Re: How to prevent from race conditions to share data between manyprocess and thread in python

    mars a écrit :
    > I use TurboGears to do some web service. TurboGears use cherrypy. When
    > web browser access this site, the cherrypy will call my python
    > program. So my program looks like a lib. When web browser access the
    > site, the http server will fock a process or gerenate a thread. I need
    > share some data or operate some files. How can I prevent from race
    > conditions. Is there any way can I lock this.
    > Thank you in advance!


    See in the cookbook:

    http://aspn.activestate.com/ASPN/search?query=locking&x=0&y=0&section=PYTHONCKBK&type=Subsection

    And test/choose one solution...
    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252495
    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203
    ....

    A+

    Laurent.
     
    Laurent Pointal, Feb 7, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. The Weiss Family

    race conditions/pulse width

    The Weiss Family, Oct 16, 2004, in forum: VHDL
    Replies:
    6
    Views:
    758
    Jim Lewis
    Oct 19, 2004
  2. Replies:
    2
    Views:
    1,201
  3. Larry Bates

    Drop folder and race conditions

    Larry Bates, Oct 9, 2007, in forum: Python
    Replies:
    1
    Views:
    294
    Steven D'Aprano
    Oct 9, 2007
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,423
    Saraswati lakki
    Jan 6, 2012
  5. kj
    Replies:
    4
    Views:
    326
    webEater
    Dec 22, 2006
Loading...

Share This Page