17
17
"""
18
18
import pwd
19
19
import os
20
+ import re
20
21
21
22
import xml .etree .ElementTree as ET
22
23
@@ -46,7 +47,7 @@ def format_template(template, *args, **kwargs):
46
47
"""
47
48
if isinstance (template , Template ):
48
49
return template .render (* args , ** kwargs )
49
- elif '{{' in template or '{%' in template :
50
+ elif '{{' in template or '{%' in template :
50
51
return Template (template ).render (* args , ** kwargs )
51
52
return template .format (* args , ** kwargs )
52
53
@@ -334,7 +335,7 @@ def start(self):
334
335
if self .user and self .user .server and self .user .server .port :
335
336
self .port = self .user .server .port
336
337
self .db .commit ()
337
- elif (jupyterhub .version_info < (0 ,7 ) and not self .user .server .port ) or \
338
+ elif (jupyterhub .version_info < (0 ,7 ) and not self .user .server .port ) or \
338
339
(jupyterhub .version_info >= (0 ,7 ) and not self .port ):
339
340
self .port = random_port ()
340
341
self .db .commit ()
@@ -356,8 +357,8 @@ def start(self):
356
357
else :
357
358
self .log .warn ('Job ' + self .job_id + ' neither pending nor running.\n ' +
358
359
self .job_status )
359
- raise RuntimeError ('The Jupyter batch job has disappeared '
360
- ' while pending in the queue or died immediately '
360
+ raise RuntimeError ('The Jupyter batch job has disappeared'
361
+ ' while pending in the queue or died immediately'
361
362
' after starting.' )
362
363
yield gen .sleep (self .startup_poll_interval )
363
364
@@ -394,7 +395,6 @@ def stop(self, now=False):
394
395
self .job_id , self .current_ip , self .port )
395
396
)
396
397
397
- import re
398
398
399
399
class BatchSpawnerRegexStates (BatchSpawnerBase ):
400
400
"""Subclass of BatchSpawnerBase that uses config-supplied regular expressions
@@ -429,15 +429,11 @@ class BatchSpawnerRegexStates(BatchSpawnerBase):
429
429
430
430
def state_ispending (self ):
431
431
assert self .state_pending_re , "Misconfigured: define state_running_re"
432
- if self .job_status and re .search (self .state_pending_re , self .job_status ):
433
- return True
434
- else : return False
432
+ return bool (self .job_status and re .search (self .state_pending_re , self .job_status ))
435
433
436
434
def state_isrunning (self ):
437
435
assert self .state_running_re , "Misconfigured: define state_running_re"
438
- if self .job_status and re .search (self .state_running_re , self .job_status ):
439
- return True
440
- else : return False
436
+ return bool (self .job_status and re .search (self .state_running_re , self .job_status ))
441
437
442
438
def state_gethost (self ):
443
439
assert self .state_exechost_re , "Misconfigured: define state_exechost_re"
@@ -450,6 +446,7 @@ def state_gethost(self):
450
446
else :
451
447
return match .expand (self .state_exechost_exp )
452
448
449
+
453
450
class TorqueSpawner (BatchSpawnerRegexStates ):
454
451
batch_script = Unicode ("""#!/bin/sh
455
452
#PBS -q {queue}@{host}
@@ -473,6 +470,7 @@ class TorqueSpawner(BatchSpawnerRegexStates):
473
470
state_running_re = Unicode (r'<job_state>R</job_state>' ).tag (config = True )
474
471
state_exechost_re = Unicode (r'<exec_host>((?:[\w_-]+\.?)+)/\d+' ).tag (config = True )
475
472
473
+
476
474
class MoabSpawner (TorqueSpawner ):
477
475
# outputs job id string
478
476
batch_submit_cmd = Unicode ('msub' ).tag (config = True )
@@ -483,6 +481,7 @@ class MoabSpawner(TorqueSpawner):
483
481
state_running_re = Unicode (r'State="Running"' ).tag (config = True )
484
482
state_exechost_re = Unicode (r'AllocNodeList="([^\r\n\t\f :"]*)' ).tag (config = True )
485
483
484
+
486
485
class UserEnvMixin :
487
486
"""Mixin class that computes values for USER, SHELL and HOME in the environment passed to
488
487
the job submission subprocess in case the batch system needs these for the batch script."""
@@ -504,6 +503,7 @@ def get_env(self):
504
503
env = self .user_env (env )
505
504
return env
506
505
506
+
507
507
class SlurmSpawner (UserEnvMixin ,BatchSpawnerRegexStates ):
508
508
"""A Spawner that just uses Popen to start local processes."""
509
509
@@ -561,6 +561,7 @@ def parse_job_id(self, output):
561
561
raise e
562
562
return id
563
563
564
+
564
565
class MultiSlurmSpawner (SlurmSpawner ):
565
566
'''When slurm has been compiled with --enable-multiple-slurmd, the
566
567
administrator sets the name of the slurmd instance via the slurmd -N
@@ -573,6 +574,7 @@ def state_gethost(self):
573
574
host = SlurmSpawner .state_gethost (self )
574
575
return self .daemon_resolver .get (host , host )
575
576
577
+
576
578
class GridengineSpawner (BatchSpawnerBase ):
577
579
batch_script = Unicode ("""#!/bin/bash
578
580
#$ -j yes
@@ -620,6 +622,7 @@ def state_gethost(self):
620
622
self .log .error ("Spawner unable to match host addr in job {0} with status {1}" .format (self .job_id , self .job_status ))
621
623
return
622
624
625
+
623
626
class CondorSpawner (UserEnvMixin ,BatchSpawnerRegexStates ):
624
627
batch_script = Unicode ("""
625
628
Executable = /bin/sh
@@ -657,6 +660,7 @@ def parse_job_id(self, output):
657
660
def cmd_formatted_for_batch (self ):
658
661
return super (CondorSpawner ,self ).cmd_formatted_for_batch ().replace ('"' ,'""' ).replace ("'" ,"''" )
659
662
663
+
660
664
class LsfSpawner (BatchSpawnerBase ):
661
665
'''A Spawner that uses IBM's Platform Load Sharing Facility (LSF) to launch notebooks.'''
662
666
@@ -701,7 +705,6 @@ def state_isrunning(self):
701
705
if self .job_status :
702
706
return self .job_status .split (' ' )[0 ].upper () == 'RUN'
703
707
704
-
705
708
def state_gethost (self ):
706
709
if self .job_status :
707
710
return self .job_status .split (' ' )[1 ].strip ()
0 commit comments