Created
January 29, 2015 16:50
-
-
Save bsmithyman/fd292b7f400ecbc50a73 to your computer and use it in GitHub Desktop.
Change all IPython parallel workers to a common directory under $HOME
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cdSame(profile=None): | |
import os | |
from IPython.parallel import Client | |
if profile: | |
rc = Client(profile=profile) | |
else: | |
rc = Client() | |
dview = rc[:] | |
home = os.getenv('HOME') | |
cwd = os.getcwd() | |
def cdrel(relpath): | |
import os | |
home = os.getenv('HOME') | |
fullpath = os.path.join(home, relpath) | |
try: | |
os.chdir(fullpath) | |
except OSError: | |
return False | |
else: | |
return True | |
if cwd.find(home) == 0: | |
relpath = cwd[len(home)+1:] | |
return all(rc[:].apply_sync(cdrel, relpath)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment