-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a7d1a1
commit 440f837
Showing
9 changed files
with
69 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
import subprocess | ||
from subprocess import TimeoutExpired | ||
import sys | ||
from pathlib import Path | ||
|
||
import pytorch_lightning | ||
|
||
|
||
def call_training_script(module_file, cli_args, method, tmpdir, timeout=60): | ||
file = Path(module_file.__file__).absolute() | ||
cli_args = cli_args.split(' ') if cli_args else [] | ||
cli_args += ['--tmpdir', str(tmpdir)] | ||
cli_args += ['--trainer_method', method] | ||
command = [sys.executable, str(file)] + cli_args | ||
|
||
# need to set the PYTHONPATH in case pytorch_lightning was not installed into the environment | ||
env = os.environ.copy() | ||
env['PYTHONPATH'] = f'{pytorch_lightning.__file__}:' + env.get('PYTHONPATH', '') | ||
|
||
# for running in ddp mode, we need to lauch it's own process or pytest will get stuck | ||
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) | ||
|
||
try: | ||
std, err = p.communicate(timeout=timeout) | ||
err = str(err.decode("utf-8")) | ||
if 'Exception' in err: | ||
raise Exception(err) | ||
except TimeoutExpired: | ||
p.kill() | ||
std, err = p.communicate() | ||
|
||
return std, err |