subprocesses and deadlocks

Discussion in 'Python' started by betatim@gmail.com, Aug 6, 2006.

  1. Guest

    Hi,

    there are many ways of solving the problem of finite buffer sizes when
    talking to a subprocess. I'd usually suggest using select() but today I
    was looking for a more readable/understandable way of doing this. Back
    in 1997 Guido himself posted a very nice solution, write your input to
    a temporary file and then read that from your new process. His posting
    can be found here:
    http://groups.google.com/group/comp...process deadlock&rnum=6&#doc_63b0a786d87ba23b

    Being a bit puzzled over this usage of tempfile I read its
    documentation and as expected it says:

    [...] The file is created using mkstemp. It will be destroyed as soon
    as it is closed (including an implicit close when the object is garbage
    collected). [...] your code should not rely on a temporary file created
    using this function having or not having a visible name in the file
    system.

    so how was Guido planning to get the contents of the file after closing
    it? Should we do a tf.flush() instead of the close to ensure everything
    is written, then read from it, using subprocess.Popen(....,stdin=tf,..)
    and only close it afterwards?

    Is it correct to assume that a named temporary file will be (sometimes)
    accesible while it has not been closed yet?

    cheers,
    tim
    , Aug 6, 2006
    #1
    1. Advertising

  2. Simon Forman Guest

    wrote:
    > Hi,
    >
    > there are many ways of solving the problem of finite buffer sizes when
    > talking to a subprocess. I'd usually suggest using select() but today I
    > was looking for a more readable/understandable way of doing this. Back
    > in 1997 Guido himself posted a very nice solution, write your input to
    > a temporary file and then read that from your new process. His posting
    > can be found here:
    > http://groups.google.com/group/comp...process deadlock&rnum=6&#doc_63b0a786d87ba23b
    >
    > Being a bit puzzled over this usage of tempfile I read its
    > documentation and as expected it says:
    >
    > [...] The file is created using mkstemp. It will be destroyed as soon
    > as it is closed (including an implicit close when the object is garbage
    > collected). [...] your code should not rely on a temporary file created
    > using this function having or not having a visible name in the file
    > system.
    >
    > so how was Guido planning to get the contents of the file after closing
    > it? Should we do a tf.flush() instead of the close to ensure everything
    > is written, then read from it, using subprocess.Popen(....,stdin=tf,..)
    > and only close it afterwards?
    >
    > Is it correct to assume that a named temporary file will be (sometimes)
    > accesible while it has not been closed yet?
    >
    > cheers,
    > tim


    When GvR wrote that around a decade ago, tempfile.mktemp() had not yet
    been deprecated. It returns "an absolute pathname of a file that did
    not exist at the time the call is made". It does not create a file,
    you have to do that yourself.

    You're quoting the docs for tempfile.TemporaryFile(). It returns a
    "file (or file-like) object", and I'd assume that you would have to
    pass this object around without closing it in order to use it in the
    manner described in GvR's post.


    http://docs.python.org/lib/module-tempfile.html
    Simon Forman, Aug 6, 2006
    #2
    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. Martin Blackstone [MVP - Exchange]

    ASP.NET Deadlocks

    Martin Blackstone [MVP - Exchange], Aug 23, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    751
    Nick Wienholt
    Aug 24, 2003
  2. Mike Carr

    Deadlocks

    Mike Carr, Jul 16, 2004, in forum: ASP .Net
    Replies:
    9
    Views:
    625
    Mike Carr
    Jul 23, 2004
  3. Rogan Dawes

    Automatically detecting deadlocks?

    Rogan Dawes, May 5, 2004, in forum: Java
    Replies:
    2
    Views:
    415
    Rogan Dawes
    May 6, 2004
  4. deadlocks

    , Dec 8, 2005, in forum: Java
    Replies:
    31
    Views:
    1,476
    Steve Horsley
    Dec 22, 2005
  5. Mc Osten

    Threads and Deadlocks

    Mc Osten, Mar 11, 2006, in forum: Ruby
    Replies:
    8
    Views:
    114
    Charles O Nutter
    Mar 15, 2006
Loading...

Share This Page