Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > popening a process in a specific working directory

Reply
Thread Tools

popening a process in a specific working directory

 
 
Michael Torrie
Guest
Posts: n/a
 
      03-05-2008
I have a small multi-threaded program that spawns a number of threads
that each spawn a particular process in a particular temporary
directory. My problem is that using os.chdir to change the working
directory before popening the process doesn't always work because
another thread might change the cwd as it starts, before the process in
this thread can start up.

I'm currently using popen2.Popen4. Is there a way to properly specify a
particular working directory when launching a process in python? I've
hacked around my problem by writing a bash wrapper script that accepts
the working directory as a parameter, changes the directory, then spawns
the original program with the arguments. This works, but I'd like a
better way.

Michael
 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      03-05-2008
On Tue, 04 Mar 2008 22:01:57 -0700, Michael Torrie <(E-Mail Removed)>
declaimed the following in comp.lang.python:

> I have a small multi-threaded program that spawns a number of threads
> that each spawn a particular process in a particular temporary
> directory. My problem is that using os.chdir to change the working
> directory before popening the process doesn't always work because
> another thread might change the cwd as it starts, before the process in
> this thread can start up.
>


Sounds like a variation of a classical "critical section"...

Wrap the os.chdir and popen calls with a common lock...

spawnLock.acquire()
os.chgdir(...)
...popen*...
spawnLock.release()

--
Wulfraed Dennis Lee Bieber KD6MOG
http://www.velocityreviews.com/forums/(E-Mail Removed) (E-Mail Removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (E-Mail Removed))
HTTP://www.bestiaria.com/
 
Reply With Quote
 
 
 
 
Sion Arrowsmith
Guest
Posts: n/a
 
      03-05-2008
Michael Torrie <(E-Mail Removed)> wrote:
>I'm currently using popen2.Popen4. Is there a way to properly specify a
>particular working directory when launching a process in python?


Switch to using subprocess.Popen and specify the cwd argument.

--
\S -- (E-Mail Removed) -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML parsing problem finding a specific element in a specific place mazdotnet ASP .Net 2 10-02-2009 10:07 AM
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning the specified directory Nathan Sokalski ASP .Net 2 09-06-2007 03:58 PM
Is ViwState Page-Specific or UserControl-Specific =?Utf-8?B?SmF2?= ASP .Net 2 08-16-2006 09:30 PM
redirect traffic on specific ip to specific interface mimiseh Cisco 3 06-05-2005 09:14 PM
How do you make sure a frameset is loaded? I'm trying to open a frameset in a new window which shows a specific html page in a specific frame ck388 Javascript 1 09-24-2003 08:32 PM



Advertisments