htcondor API Reference

This page is an exhaustive reference of the API exposed by the htcondor module. It is not meant to be a tutorial for new users but rather a helpful guide for those who already understand the basic usage of the module.

Interacting with Collectors

class htcondor.Collector(pool)

Client object for a remote condor_collector. The Collector can be used to:

  • Locate a daemon.

  • Query the condor_collector for one or more specific ClassAds.

  • Advertise a new ad to the condor_collector.

Parameters

pool (str or list[str]) – A host:port pair specified for the remote collector (or a list of pairs for HA setups). If omitted, the value of configuration parameter COLLECTOR_HOST is used.

locate(daemon_type, name) → object :

Query the condor_collector for a particular daemon.

Parameters
  • daemon_type (DaemonTypes) – The type of daemon to locate.

  • name (str) – The name of daemon to locate. If not specified, it searches for the local daemon.

Returns

a minimal ClassAd of the requested daemon, sufficient only to contact the daemon; typically, this limits to the MyAddress attribute.

Return type

ClassAd

locateAll(daemon_type) → object :

Query the condor_collector daemon for all ClassAds of a particular type. Returns a list of matching ClassAds.

Parameters

daemon_type (DaemonTypes) – The type of daemon to locate.

Returns

Matching ClassAds

Return type

list[ClassAd]

query(ad_type=htcondor.htcondor.AdTypes.Any, constraint='', projection=[], statistics='') → object :

Query the contents of a condor_collector daemon. Returns a list of ClassAds that match the constraint parameter.

Parameters
  • ad_type (AdTypes) – The type of ClassAd to return. If not specified, the type will be ANY_AD.

  • constraint (str or ExprTree) – A constraint for the collector query; only ads matching this constraint are returned. If not specified, all matching ads of the given type are returned.

  • projection (list[str]) – A list of attributes to use for the projection. Only these attributes, plus a few server-managed, are returned in each ClassAd.

  • statistics (list[str]) – Statistics attributes to include, if they exist for the specified daemon.

Returns

A list of matching ads.

Return type

list[ClassAd]

directQuery(daemon_type, name='', projection=[], statistics='') → object :

Query the specified daemon directly for a ClassAd, instead of using the ClassAd from the condor_collector daemon. Requires the client library to first locate the daemon in the collector, then querying the remote daemon.

Parameters
  • daemon_type (DaemonTypes) – Specifies the type of the remote daemon to query.

  • name (str) – Specifies the daemon’s name. If not specified, the local daemon is used.

  • projection (list[str]) – is a list of attributes requested, to obtain only a subset of the attributes from the daemon’s ClassAd.

  • statistics (str) – Statistics attributes to include, if they exist for the specified daemon.

Returns

The ad of the specified daemon.

Return type

ClassAd

advertise(ad_list, command='UPDATE_AD_GENERIC', use_tcp=True) → None :

Advertise a list of ClassAds into the condor_collector.

Parameters
  • ad_list (list[ClassAds]) – ClassAds to advertise.

  • command (str) – An advertise command for the remote condor_collector. It defaults to UPDATE_AD_GENERIC. Other commands, such as UPDATE_STARTD_AD, may require different authorization levels with the remote daemon.

  • use_tcp (bool) – When set to True, updates are sent via TCP. Defaults to True.

class htcondor.DaemonTypes

An enumeration of different types of daemons available to HTCondor.

The values of the enumeration are:

None
Any

Any type of daemon; useful when specifying queries where all matching daemons should be returned.

Master

Ads representing the condor_master.

Schedd

Ads representing the condor_schedd.

Startd

Ads representing the resources on a worker node.

Collector

Ads representing the condor_collector.

Negotiator

Ads representing the condor_negotiator.

HAD

Ads representing the high-availability daemons (condor_had).

Generic

All other ads that are not categorized as above.

Credd
class htcondor.AdTypes

A list of different types of ads that may be kept in the condor_collector.

The values of the enumeration are:

None
Any

Type representing any matching ad. Useful for queries that match everything in the collector.

Generic

Generic ads, associated with no particular daemon.

Startd

Startd ads, produced by the condor_startd daemon. Represents the available slots managed by the startd.

StartdPrivate

The “private” ads, containing the claim IDs associated with a particular slot. These require additional authorization to read as the claim ID may be used to run jobs on the slot.

Schedd

Schedd ads, produced by the condor_schedd daemon.

Master

Master ads, produced by the condor_master daemon.

Collector

Ads from the condor_collector daemon.

Negotiator

Negotiator ads, produced by the condor_negotiator daemon.

Submitter

Ads describing the submitters with available jobs to run; produced by the condor_schedd and read by the condor_negotiator to determine which users need a new negotiation cycle.

Grid

Ads associated with the grid universe.

HAD

Ads produced by the condor_had.

License

License ads. These do not appear to be used by any modern HTCondor daemon.

Credd
Defrag
Accounting

Interacting with Schedulers

class htcondor.Schedd(location_ad)

Client object for a condor_schedd.

Parameters

location_ad (ClassAd or DaemonLocation) – An Ad describing the location of the remote condor_schedd daemon, as returned by the Collector.locate() method, or a tuple of type DaemonLocation as returned by Schedd.location(). If the parameter is omitted, the local condor_schedd daemon is used.

transaction(flags=0, continue_txn=False) → Transaction :

Start a transaction with the condor_schedd.

Starting a new transaction while one is ongoing is an error unless the continue_txn flag is set.

Parameters
  • flags (TransactionFlags) – Flags controlling the behavior of the transaction, defaulting to 0.

  • continue_txn (bool) – Set to True if you would like this transaction to extend any pre-existing transaction; defaults to False. If this is not set, starting a transaction inside a pre-existing transaction will cause an exception to be thrown.

Returns

A transaction context manager object.

query(constraint='true', projection=[], callback=None, limit=- 1, opts=htcondor.htcondor.QueryOpts.Default) → object :

Query the condor_schedd daemon for job ads.

Warning

This returns a list of ClassAd objects, meaning all results must be held in memory simultaneously. This may be memory-intensive for queries that return many and/or large jobs ads. If you are retrieving many large ads, consider using xquery() instead to reduce memory requirements.

Parameters
  • constraint (str or ExprTree) – A query constraint. Only jobs matching this constraint will be returned. Defaults to 'true', which means all jobs will be returned.

  • projection (list[str]) – Attributes that will be returned for each job in the query. At least the attributes in this list will be returned, but additional ones may be returned as well. An empty list (the default) returns all attributes.

  • callback – A callable object; if provided, it will be invoked for each ClassAd. The return value (if not None) will be added to the returned list instead of the ad.

  • limit (int) – The maximum number of ads to return; the default (-1) is to return all ads.

  • opts (QueryOpts.) – Additional flags for the query; these may affect the behavior of the condor_schedd.

Returns

ClassAds representing the matching jobs.

Return type

list[ClassAd]

xquery(constraint='true', projection=[], limit=- 1, opts=htcondor.htcondor.QueryOpts.Default, name=None) → QueryIterator :

Query the condor_schedd daemon for job ads.

Warning

This returns an iterator of ClassAd objects, which means you may not need to hold all of the ads returned by the query in memory simultaneously. However, this method holds a connection open to the schedd, and a fork of the schedd will remain active, until you finish iterating. If you are not retrieving many large ads, consider using query() instead to reduce load on the schedd.

Parameters
  • constraint (str or ExprTree) – A query constraint. Only jobs matching this constraint will be returned. Defaults to 'true', which means all jobs will be returned.

  • projection (list[str]) – Attributes that will be returned for each job in the query. At least the attributes in this list will be returned, but additional ones may be returned as well. An empty list (the default) returns all attributes.

  • limit (int) – A limit on the number of matches to return. The default (-1) indicates all matching jobs should be returned.

  • opts (QueryOpts) – Additional flags for the query, from QueryOpts.

  • name (str) – A tag name for the returned query iterator. This string will always be returned from the QueryIterator.tag() method of the returned iterator. The default value is the condor_schedd’s name. This tag is useful to identify different queries when using the poll() function.

Returns

An iterator for the matching job ads

Return type

QueryIterator

act(action, job_spec, reason=None) → object :

Change status of job(s) in the condor_schedd daemon. The return value is a ClassAd object describing the number of jobs changed.

This will throw an exception if no jobs are matched by the constraint.

Parameters
  • action (JobAction) – The action to perform; must be of the enum JobAction.

  • job_spec (list[str] or str) – The job specification. It can either be a list of job IDs, or an ExprTree or string specifying a constraint. Only jobs matching this description will be acted upon.

  • reason (str) – The reason for the action. If omitted, the reason will be “Python-initiated action”.

edit(job_spec, attr, value) → EditResult :

Edit one or more jobs in the queue.

This will throw an exception if no jobs are matched by the job_spec constraint.

Parameters
  • job_spec (list[str] or str) – The job specification. It can either be a list of job IDs or a string specifying a constraint. Only jobs matching this description will be acted upon.

  • attr (str) – The name of the attribute to edit.

  • value (str or ExprTree) – The new value of the attribute. It should be a string, which will be converted to a ClassAd expression, or an ExprTree object. Be mindful of quoting issues; to set the value to the string foo, one would set the value to ''foo''

Returns

An EditResult containing the number of jobs that were edited.

Return type

EditResult

history(constraint, projection, match=- 1, since=None) → HistoryIterator :

Fetch history records from the condor_schedd daemon.

Parameters
  • constraint (str or ExprTree) – A query constraint. Only jobs matching this constraint will be returned. Defaults to 'true', which means all jobs will be returned.

  • projection (list[str]) – Attributes that will be returned for each job in the query. At least the attributes in this list will be returned, but additional ones may be returned as well. An empty list (the default) returns all attributes.

  • match (int) – An limit on the number of jobs to include; the default (-1) indicates to return all matching jobs.

Returns

All matching ads in the Schedd history, with attributes according to the projection keyword.

Return type

HistoryIterator

submit(description, count=1, spool=False, ad_results=None, itemdata=None) → object :

Submit one or more jobs to the condor_schedd daemon.

This method requires the invoker to provide a Submit object that describes the jobs to submit. The return value will be a :class::~htcondor.SubmitResult that contains the cluster ID and ClassAd of the submitted jobs.

For backward compatibility, this method will also accept a ClassAd that describes a single job to submit, but use of this form of is deprecated. Use submit_raw to submit raw job ClassAds. If the deprecated form is used the return value will be the cluster ID, and ad_results will optionally be the actual job ClassAds that were submitted.

Parameters
  • description (Submit (or deprecated ClassAd)) – The Submit description or ClassAd describing the job cluster.

  • count (int) – The number of jobs to submit to the job cluster. Defaults to 1.

  • spool (bool) – If True, jobs will be submitted in a spooling hold mode so that input files can be spooled to a remote condor_schedd daemon before starting the jobs. This parameter is necessary for jobs submitted to a remote condor_schedd that use HTCondor file transfer.

  • ad_results (list[ClassAd]) – deprecated. If set to a list and a raw job ClassAd is passed as the first argument, the list object will contain the job ads that were submitted. These are passed to the spool method to send files to the remote Schedd.

Returns

a SubmitResult, containing the cluster ID, cluster ClassAd and range of Job ids of the submitted job(s). If using the deprecated first argument, the return value will be an int and ad_results may contain submitted jobs ClassAds.

Return type

SubmitResult or int

submitMany(cluster_ad, proc_ads, spool=False, ad_results=None) → int :

Submit multiple jobs to the condor_schedd daemon, possibly including several distinct processes.

Parameters
  • cluster_ad (ClassAd) – The base ad for the new job cluster; this is the same format as in the submit() method.

  • proc_ads (list) – A list of 2-tuples; each tuple has the format of (proc_ad, count). For each list entry, this will result in count jobs being submitted inheriting from both cluster_ad and proc_ad.

  • spool (bool) – If True, the clinent inserts the necessary attributes into the job for it to have the input files spooled to a remote condor_schedd daemon. This parameter is necessary for jobs submitted to a remote condor_schedd that use HTCondor file transfer.

  • ad_results (list[ClassAd]) – If set to a list, the list object will contain the job ads resulting from the job submission. These are needed for interacting with the job spool after submission.

Returns

The newly created cluster ID.

Return type

int

spool(ad_list) → None :

Spools the files specified in a list of job ClassAds to the condor_schedd.

Parameters

ad_list (list[ClassAds]) – A list of job descriptions; typically, this is the list filled by the ad_results argument of the submit() method call.

Raises

RuntimeError – if there are any errors.

retrieve(arg1, arg2) → None :

Retrieve the output sandbox from one or more jobs.

Parameters

job_spec (str or list[ClassAd]) – An expression matching the list of job output sandboxes to retrieve.

refreshGSIProxy(cluster, proc, proxy_filename, lifetime) → int :

Refresh the GSI proxy of a job; the job’s proxy will be replaced the contents of the provided proxy_filename.

Note

Depending on the lifetime of the proxy in proxy_filename, the resulting lifetime may be shorter than the desired lifetime.

Parameters
  • cluster (int) – Cluster ID of the job to alter.

  • proc (int) – Process ID of the job to alter.

  • proxy_filename (str) – The name of the file containing the new proxy for the job.

  • lifetime (int) – Indicates the desired lifetime (in seconds) of the delegated proxy. A value of 0 specifies to not shorten the proxy lifetime. A value of -1 specifies to use the value of configuration variable DELEGATE_JOB_GSI_CREDENTIALS_LIFETIME.

reschedule() → None :

Send reschedule command to the schedd.

class htcondor.JobAction

An enumeration describing the actions that may be performed on a job in queue.

The values of the enumeration are:

Hold

Put a job on hold, vacating a running job if necessary. A job will stay in the hold state until explicitly acted upon by the admin or owner.

Release

Release a job from the hold state, returning it to Idle.

Suspend

Suspend the processes of a running job (on Unix platforms, this triggers a SIGSTOP). The job’s processes stay in memory but no longer get scheduled on the CPU.

Continue

Continue a suspended jobs (on Unix, SIGCONT). The processes in a previously suspended job will be scheduled to get CPU time again.

Remove

Remove a job from the Schedd’s queue, cleaning it up first on the remote host (if running). This requires the remote host to acknowledge it has successfully vacated the job, meaning Remove may not be instantaneous.

RemoveX

Immediately remove a job from the schedd queue, even if it means the job is left running on the remote resource.

Vacate

Cause a running job to be killed on the remote resource and return to idle state. With Vacate, jobs may be given significant time to cleanly shut down.

VacateFast

Vacate a running job as quickly as possible, without providing time for the job to cleanly terminate.

class htcondor.TransactionFlags

Enumerated flags affecting the characteristics of a transaction.

The values of the enumeration are:

NonDurable

Non-durable transactions are changes that may be lost when the condor_schedd crashes. NonDurable is used for performance, as it eliminates extra fsync() calls.

SetDirty

This marks the changed ClassAds as dirty, causing an update notification to be sent to the condor_shadow and the condor_gridmanager, if they are managing the job.

ShouldLog

Causes any changes to the job queue to be logged in the relevant job event log.

class htcondor.QueryOpts

Enumerated flags sent to the condor_schedd during a query to alter its behavior.

The values of the enumeration are:

Default

Queries should use default behaviors, and return jobs for all users.

AutoCluster

Instead of returning job ads, return an ad per auto-cluster.

GroupBy

Instead of returning job ads, return an ad for each unique combination of values for the attributes in the projection. Similar to AutoCluster, but using the projection as the significant attributes for auto-clustering.

DefaultMyJobsOnly

Queries should use all default behaviors, and return jobs only for the current user.

SummaryOnly

Instead of returning job ads, return only the final summary ad.

IncludeClusterAd

Query should return raw cluster ads as well as job ads if the cluster ads match the query constraint.

class htcondor.BlockingMode

An enumeration that controls the behavior of query iterators once they are out of data.

The values of the enumeration are:

Blocking

Sets the iterator to block until more data is available.

NonBlocking

Sets the iterator to return immediately if additional data is not available.

class htcondor.HistoryIterator(*args, **kwargs)

An iterator over ads in the history produced by Schedd.history().

class htcondor.QueryIterator(*args, **kwargs)

An iterator class for managing results of the Schedd.query() and Schedd.xquery() methods.

nextAdsNonBlocking() → list :

Retrieve as many ads are available to the iterator object.

If no ads are available, returns an empty list. Does not throw an exception if no ads are available or the iterator is finished.

Returns

Zero-or-more job ads.

Return type

list[ClassAd]

tag() → str :

Retrieve the tag associated with this iterator; when using the poll() method, this is useful to distinguish multiple iterators.

Returns

The query’s tag.

done() → bool :
Returns

True if the iterator is finished; False otherwise.

Return type

bool

watch() → int :

Returns an inotify-based file descriptor; if this descriptor is given to a select() instance, select will indicate this file descriptor is ready to read whenever there are more jobs ready on the iterator.

If inotify is not available on this platform, this will return -1.

Returns

A file descriptor associated with this query.

Return type

int

htcondor.poll(queries, timeout_ms=20000) → BulkQueryIterator :

Wait on the results of multiple query iterators.

This function returns an iterator which yields the next ready query iterator. The returned iterator stops when all results have been consumed for all iterators.

Parameters

active_queries (list[QueryIterator]) – Query iterators as returned by xquery().

Returns

An iterator producing the ready QueryIterator.

Return type

BulkQueryIterator

class htcondor.BulkQueryIterator(*args, **kwargs)

Returned by poll(), this iterator produces a sequence of QueryIterator objects that have ads ready to be read in a non-blocking manner.

Once there are no additional available iterators, poll() must be called again.

class htcondor.JobStatus(value)

An enumeration of HTCondor job status values.

IDLE
RUNNING
REMOVED
COMPLETED
HELD
TRANSFERRING_OUTPUT
SUSPENDED

Submitting Jobs

class htcondor.Submit(*args, **kwargs)

An object representing a job submit description. It uses the same submit language as condor_submit.

The submit description contains key = value pairs and implements the python dictionary protocol, including the get, setdefault, update, keys, items, and values methods.

object __init__(tuple args, dict kwds) :

param input

Submit descriptors as key = value pairs in a dictionary, or as keyword arguments, or as a string containing the text of a submit file. For example, these calls all produce identical submit descriptions:

from_file = htcondor.Submit(
    """
    executable = /bin/sleep
    arguments = 5s
    My.CustomAttribute = "foobar"
    """
)

# we need to quote the string "foobar" correctly
from_dict = htcondor.Submit({
    "executable": "/bin/sleep",
    "arguments": "5s",
    "My.CustomAttribute": classad.quote("foobar"),
})

# the **{} is a trick to get a keyword argument that contains a .
from_kwargs = htcondor.Submit(
    executable = "/bin/sleep",
    arguments = "5s",
    **{
        "My.CustomAttribute": classad.quote("foobar"),
    }
)

If a string is used, it may include a single condor_submit QUEUE statement. The arguments to the QUEUE statement will be stored in the QArgs member of this class and used when Submit.queue() or Submit.queue_with_itemdata() are called. If omitted, the submit description is initially empty.

type input

dict or str

queue(txn, count=0, ad_results=None) → int :

Submit the current object to a remote queue.

Parameters
  • txn (Transaction) – An active transaction object (see Schedd.transaction()).

  • count (int) – The number of jobs to create (defaults to 0). If not specified, or a value of 0 is given the QArgs member of this class is used to determine the number of procs to submit. If no QArgs were specified, one job is submitted.

  • ad_results – A list to receive the ClassAd resulting from this submit. As with Schedd.submit(), this is often used to later spool the input files.

Returns

The ClusterID of the submitted job(s).

Return type

int

Raises

RuntimeError – if the submission fails.

queue_with_itemdata(txn, count=1, itemdata=None) → SubmitResult :

Submit the current object to a remote queue.

Parameters
  • txn (Transaction) – An active transaction object (see Schedd.transaction()).

  • count (int) – A queue count for each item from the iterator, defaults to 1.

  • from – an iterator of strings or dictionaries containing the itemdata for each job as in queue in or queue from.

Returns

a SubmitResult, containing the cluster ID, cluster ClassAd and range of Job ids Cluster ID of the submitted job(s).

Return type

SubmitResult

Raises

RuntimeError – if the submission fails.

expand(attr) → str :

Expand all macros for the given attribute.

Parameters

attr (str) – The name of the relevant attribute.

Returns

The value of the given attribute; all macros are expanded.

Return type

str

jobs(count=0, itemdata=None, clusterid=1, procid=0, qdate=0, owner='') → SubmitJobsIterator :

Turn the current object into a sequence of simulated job ClassAds

Parameters
  • count (int) – the queue count for each item in the from list, defaults to 1

  • from – a iterator of strings or dictionaries containing the itemdata for each job e.g. ‘queue in’ or ‘queue from’

  • clusterid (int) – the value to use for ClusterId when making job ads, defaults to 1

  • procid (int) – the initial value for ProcId when making job ads, defaults to 0

  • qdate (str) – a UNIX timestamp value for the QDATE attribute of the jobs, 0 means use the current time.

  • owner (str) – a string value for the Owner attribute of the job

Returns

An iterator for the resulting job ads.

Raises

RuntimeError – if valid job ads cannot be made

procs(count=0, itemdata=None, clusterid=1, procid=0, qdate=0, owner='') → SubmitJobsIterator :

Turn the current object into a sequence of simulated job proc ClassAds. The first ClassAd will be the cluster ad plus a ProcId attribute

Parameters
  • count (int) – the queue count for each item in the from list, defaults to 1

  • from – a iterator of strings or dictionaries containing the foreach data e.g. ‘queue in’ or ‘queue from’

  • clusterid (int) – the value to use for ClusterId when making job ads, defaults to 1

  • procid (int) – the initial value for ProcId when making job ads, defaults to 0

  • qdate (str) – a UNIX timestamp value for the QDATE attribute of the jobs, 0 means use the current time.

  • owner (str) – a string value for the Owner attribute of the job

Returns

An iterator for the resulting job ads.

Raises

RuntimeError – if valid job ads cannot be made

itemdata(qargs='') → QueueItemsIterator :

Create an iterator over itemdata derived from a queue statement.

For example itemdata("matching *.dat") would return an iterator of filenames that end in .dat from the current directory. This is the same iterator used by condor_submit when processing QUEUE statements.

Parameters

queue (str) – a submit queue statement, or the arguments to a submit queue statement.

Returns

An iterator for the resulting items

getQArgs() → str :

Returns arguments specified in the QUEUE statement passed to the contructor. These are the arguments that will be used by the Submit.queue() and Submit.queue_with_itemdata() methods if not overridden by arguments to those methods.

setQArgs(args) → None :

Sets the arguments to be used by subsequent calls to the Submit.queue() and Submit.queue_with_itemdata() methods if not overridden by arguments to those methods.

Parameters

args (str) – The arguments to pass to the QUEUE statement.

static from_dag(filename, options={}) → Submit :

Constructs a new Submit that could be used to submit the DAG described by the file found at filename.

This static method essentially does the first half of the work that condor_submit_dag does: it produces the submit description for the DAGMan job that will execute the DAG. However, in addition to writing this submit description to disk, it also produces a Submit object with the same information that can be submitted via the normal Python bindings submit machinery.

Parameters
  • filename (str) – The path to the DAG description file.

  • options (dict) – Additional arguments to condor_submit_dag. Supports dagman (str), force (bool), schedd-daemon-ad-file (str), schedd-address-file (str), AlwaysRunPost (bool), maxidle (int), maxjobs (int), MaxPre (int), MaxPost (int), UseDagDir (bool), debug (int), outfile_dir (str), config (str), batch-name (str), AutoRescue (bool), DoRescueFrom (int), AllowVersionMismatch (bool), do_recurse (bool), update_submit (bool), import_env (bool), DumpRescue (bool), valgrind (bool), priority (int), suppress_notification (bool), DoRecov (bool)

Returns

A Submit description for the DAG described in filename

Return type

Submit

class htcondor.QueueItemsIterator(*args, **kwargs)

An iterator over itemdata produced by Submit.itemdata().

class htcondor.SubmitResult
cluster() → int :
Returns

the ClusterID of the submitted jobs.

Return type

int

clusterad() → ClassAd :
Returns

the cluster Ad of the submitted jobs.

Return type

classad.ClassAd

first_proc() → int :
Returns

the first ProcID of the submitted jobs.

Return type

int

num_procs() → int :
Returns

the number of submitted jobs.

Return type

int

Interacting with Negotiators

class htcondor.Negotiator(ad)

Warning

Negotiator is deprecated since v8.9.8 and will be removed in a future release.

This class provides a query interface to the condor_negotiator. It primarily allows one to query and set various parameters in the fair-share accounting.

Parameters

location_ad (ClassAd or DaemonLocation) – A ClassAd or DaemonLocation describing the condor_negotiator location and version. If omitted, the default pool negotiator is assumed.

deleteUser(user) → None :

Delete all records of a user from the Negotiator’s fair-share accounting.

Parameters

user (str) – A fully-qualified user name (USER@DOMAIN).

getPriorities(rollup) → list :

Retrieve the pool accounting information, one per entry. Returns a list of accounting ClassAds.

Parameters

rollup (bool) – Set to True if accounting information, as applied to hierarchical group quotas, should be summed for groups and subgroups.

Returns

A list of accounting ads, one per entity.

Return type

list[ClassAd]

getResourceUsage(user) → list :

Get the resources (slots) used by a specified user.

Parameters

user (str) – A fully-qualified user name (USER@DOMAIN).

Returns

List of ads describing the resources (slots) in use.

Return type

list[ClassAd]

resetAllUsage() → None :

Reset all usage accounting. All known user records in the negotiator are deleted.

resetUsage(user) → None :

Reset all usage accounting of the specified user.

Parameters

user (str) – A fully-qualified user name (USER@DOMAIN).

setBeginUsage(user, value) → None :

Manually set the time that a user begins using the pool.

Parameters
  • user (str) – A fully-qualified user name (USER@DOMAIN).

  • value (int) – The Unix timestamp of initial usage.

setLastUsage(user, value) → None :

Manually set the time that a user last used the pool.

Parameters
  • user (str) – A fully-qualified user name (USER@DOMAIN).

  • value (int) – The Unix timestamp of last usage.

setFactor(user, factor) → None :

Set the priority factor of a specified user.

Parameters
  • user (str) – A fully-qualified user name (USER@DOMAIN).

  • factor (float) – The priority factor to be set for the user; must be greater-than or equal-to 1.0.

setPriority(user, prio) → None :

Set the real priority of a specified user.

Parameters
  • user (str) – A fully-qualified user name (USER@DOMAIN).

  • prio (float) – The priority to be set for the user; must be greater-than 0.0.

setUsage(user, usage) → None :

Set the accumulated usage of a specified user.

Parameters
  • user (str) – A fully-qualified user name (USER@DOMAIN).

  • usage (float) – The usage, in hours, to be set for the user.

Managing Starters and Claims

class htcondor.Startd(ad=None)

A class that represents a Startd.

Parameters

locaton_ad – A ClassAd or DaemonLocation describing the the startd location and version. If omitted, the local startd is assumed.

drainJobs(drain_type=0, resume_on_completion=False, check_expr='true', start_expr='false') → str :

Begin draining jobs from the startd.

Parameters
  • drain_type (DrainTypes) – How fast to drain the jobs. Defaults to DRAIN_GRACEFUL if not specified.

  • resume_on_completion (bool) – Whether the startd should start accepting jobs again once draining is complete. Otherwise, it will remain in the drained state. Defaults to False.

  • check_expr (str or ExprTree) – An expression string that must evaluate to true for all slots for draining to begin. Defaults to 'true'.

  • start_expr (str or ExprTree) – The expression that the startd should use while draining.

Returns

An opaque request ID that can be used to cancel draining via Startd.cancelDrainJobs()

Return type

str

cancelDrainJobs(request_id='') → None :

Cancel a draining request.

Parameters

request_id (str) – Specifies a draining request to cancel. If not specified, all draining requests for this startd are canceled.

class htcondor.DrainTypes

Draining policies that can be sent to a condor_startd.

The values of the enumeration are:

Fast
Graceful
Quick
class htcondor.VacateTypes

Vacate policies that can be sent to a condor_startd.

The values of the enumeration are:

Fast
Graceful

Security Management

class htcondor.Credd(ad=None)

A class for sending Credential commands to a Credd, Schedd or Master.

Parameters

location_ad (ClassAd or DaemonLocation) – A ClassAd or DaemonLocation describing the Credd, Schedd or Master location. If omitted, the local schedd is assumed.

add_password(password, user='') → None :

Store the password in the Credd for the current user (or for the given user).

Parameters
  • password (str) – The password.

  • user (str) – Which user to store the credential for (defaults to the current user).

delete_password(user='') → None :

Delete the password in the Credd for the current user (or for the given user).

Parameters

user (str) – Which user to store the credential for (defaults to the current user).

query_password(user='') → bool :

Check to see if the current user (or the given user) has a password stored in the Credd.

Parameters

user (str) – Which user to store the credential for (defaults to the current user).

Returns

bool

add_user_cred(credtype, credential, user='') → None :

Store a credential in the Credd for the current user (or for the given user).

Parameters
  • credtype (CredTypes) – The type of credential to store.

  • credential (bytes) – The credential to store.

  • user (str) – Which user to store the credential for (defaults to the current user).

delete_user_cred(credtype, user='') → None :

Delete a credential of the given credtype for the current user (or for the given user).

Parameters
  • credtype (CredTypes) – The type of credential to delete.

  • user (str) – Which user to store the credential for (defaults to the current user).

query_user_cred(credtype, user='') → int :

Query whether the current user (or the given user) has a credential of the given type stored.

Parameters
  • credtype (CredTypes) – The type of credential to query for.

  • user (str) – Which user to store the credential for (defaults to the current user).

Returns

The time that the user credential was last updated, or None if there is no credential

add_user_service_cred(credtype, credential, service, handle='', user='') → None :

Store a credential in the Credd for the current user, or for the given user.

To specify multiple credential for the same service (e.g., you want to transfer files from two different accounts that are on the same service), give each a unique handle.

Parameters
  • credtype (CredTypes) – The type of credential to store.

  • credential (bytes) – The credential to store.

  • service (str) – The service name.

  • handle (str) – Optional service handle (defaults to no handle).

  • user (str) – Which user to store the credential for (defaults to the current user).

delete_user_service_cred(credtype, service, handle='', user='') → None :

Delete a credential of the given credtype for service service for the current user (or for the given user).

Parameters
  • credtype (CredTypes) – The type of credential to delete.

  • service (str) – The service name.

  • handle (str) – Optional service handle (defaults to no handle).

  • user (str) – Which user to store the credential for (defaults to the current user).

query_user_service_cred(credtype, service, handle='', user='') → CredStatus :

Query whether the current user (or the given user) has a credential of the given credtype stored.

Parameters
  • credtype (CredTypes) – The type of credential to check storage for.

  • service (str) – The service name.

  • handle (str) – Optional service handle (defaults to no handle).

  • user (str) – Which user to store the credential for (defaults to the current user).

Returns

CredStatus

check_user_service_creds(credtype, services, user='') → CredCheck :

Check to see if the current user (or the given user) has a given set of service credentials, and if any credentials are missing, create a temporary URL that can be used to acquire the missing service credentials.

Parameters
  • credtype (CredTypes) – The type of credentials to check for.

  • services (List[classad.ClassAd]) – The list of services that are needed.

  • user (str) – Which user to store the credential for (defaults to the current user).

Returns

CredCheck

class htcondor.CredTypes

The types of credentials that can be managed by a condor_credd.

The values of the enumeration are:

Password
Kerberos
OAuth
class htcondor.CredCheck(*args, **kwargs)
class htcondor.CredStatus(*args, **kwargs)
class htcondor.SecMan(arg1)

A class that represents the internal HTCondor security state.

If a security session becomes invalid, for example, because the remote daemon restarts, reuses the same port, and the client continues to use the session, then all future commands will fail with strange connection errors. This is the only mechanism to invalidate in-memory sessions.

The SecMan can also behave as a context manager; when created, the object can be used to set temporary security configurations that only last during the lifetime of the security object.

invalidateAllSessions() → None :

Invalidate all security sessions. Any future connections to a daemon will cause a new security session to be created.

ping(ad, command='DC_NOP') → ClassAd :

Perform a test authorization against a remote daemon for a given command.

Parameters
  • ad (str or ClassAd) – The ClassAd of the daemon as returned by Collector.locate(); alternately, the sinful string can be given directly as the first parameter.

  • command – The DaemonCore command to try; if not given, 'DC_NOP' will be used.

Returns

An ad describing the results of the test security negotiation.

Return type

ClassAd

getCommandString(command_int) → str :

Return the string name corresponding to a given integer command.

Parameters

command_int (int) – The integer command to get the string name of.

setConfig(key, value) → None :

Set a temporary configuration variable; this will be kept for all security sessions in this thread for as long as the SecMan object is alive.

Parameters
  • key (str) – Configuration key to set.

  • value (str) – Temporary value to set.

setGSICredential(filename) → None :

Set the GSI credential to be used for security negotiation.

Parameters

filename (str) – File name of the GSI credential.

setPoolPassword(new_pass) → None :

Set the pool password.

Parameters

new_pass (str) – Updated pool password to use for new security negotiations.

setTag(tag) → None :

Set the authentication context tag for the current thread.

All security sessions negotiated with the same tag will only be utilized when that tag is active.

For example, if thread A has a tag set to 'Joe' and thread B has a tag set to 'Jane', then all security sessions negotiated for thread A will not be used for thread B.

Parameters

tag (str) – New tag to set.

setToken(token) → None :

Set the token used for auth.

Parameters

token (Token) – The object representing the token contents

class htcondor.Token(contents)

A class representing a generated HTCondor authentication token.

Parameters

contents (str) – The contents of the token.

write(tokenfile=None) → None :

Write the contents of the token into the appropriate token directory on disk.

Parameters

tokenfile – Filename inside the user token directory where the token will be written.

class htcondor.TokenRequest(identity='', bounding_set=None, lifetime=- 1)

A class representing a request for a HTCondor authentication token.

Parameters
  • identity (str) – Requested identity from the remote daemon (the empty string implies condor user).

  • bounding_set (list[str]) – A list of authorizations that the token is restricted to.

  • lifetime (int) – Requested lifetime, in seconds, that the token will be valid for.

done() → bool :

Check to see if the token request has completed.

Returns

True if the request is complete; False otherwise. May throw an exception.

Return type

bool

property request_id

The ID of the request at the remote daemon.

result(timeout=0) → Token :

Return the result of the token request. Will block until the token request is approved or the timeout is hit (a timeoute of 0, the default, indicates this method may block indefinitely).

Returns

The token resulting from this request.

Return type

Token

submit(ad=None) → None :

Submit the token request to a remote daemon.

Parameters

ad (ClassAd) – ClassAd describing the location of the remote daemon.

Reading Job Events

class htcondor.JobEventLog(filename)

Reads user job event logs from filename.

By default, it waits for new events, but it may be used to poll for them:

import htcondor

jel = htcondor.JobEventLog("file.log")

# Read all currently-available events without blocking.
for event in jel.events(stop_after=0):
    print(event)

print("We found the the end of file")

A pickled JobEventLog resumes iterating over events where it left off if and only if, after being unpickled, the job event log file is identical except for appended events.

Parameters

filename (str) – A file containing a user job event log.

events(stop_after) → object :

Return an iterator over JobEvent objects from the filename given in the constructor.

Parameters

stop_after (int) – After how many seconds should the iterator stop waiting for new events? If None (the default), wait forever. If 0, never wait.

close() → None :

Closes any open underlying file. This object will no longer iterate.

class htcondor.JobEvent

Represents a single job event from the job event log. Use JobEventLog to get an iterator over the job events from a file.

Because all events have type, cluster, proc, and timestamp, those are accessed via attributes (see below).

The rest of the information in the JobEvent can be accessed by key. JobEvent behaves like a read-only Python dict, with get, keys, items, and values methods, and supports len and in (if "attribute" in job_event, for example).

Attention

Although the attribute type is a JobEventType type, when acting as dictionary, a JobEvent object returns types as if it were a ClassAd, so comparisons to enumerated values must use the == operator. (No current event type has ExprTree values.)

type

The event type.

Return type

JobEventType

cluster

The clusterid of the job the event is for.

Return type

int

proc

The procid of the job the event is for.

Return type

int

timestamp

The timestamp of the event.

Return type

str

get(key, default=None) → object :

As dict.get().

keys() → list :

As dict.keys().

values() → list :

As dict.values().

items() → list :

As dict.items().

class htcondor.JobEventType

The type event of a user log event; corresponds to ULogEventNumber in the C++ source.

The values of the enumeration are:

SUBMIT
EXECUTE
EXECUTABLE_ERROR
CHECKPOINTED
JOB_EVICTED
JOB_TERMINATED
IMAGE_SIZE
SHADOW_EXCEPTION
GENERIC
JOB_ABORTED
JOB_SUSPENDED
JOB_UNSUSPENDED
JOB_HELD
JOB_RELEASED
NODE_EXECUTE
NODE_TERMINATED
POST_SCRIPT_TERMINATED
GLOBUS_SUBMIT
GLOBUS_SUBMIT_FAILED
GLOBUS_RESOURCE_UP
GLOBUS_RESOURCE_DOWN
REMOTE_ERROR
JOB_DISCONNECTED
JOB_RECONNECTED
JOB_RECONNECT_FAILED
GRID_RESOURCE_UP
GRID_RESOURCE_DOWN
GRID_SUBMIT
JOB_AD_INFORMATION
JOB_STATUS_UNKNOWN
JOB_STATUS_KNOWN
JOB_STAGE_IN
JOB_STAGE_OUT
ATTRIBUTE_UPDATE
PRESKIP
CLUSTER_SUBMIT
CLUSTER_REMOVE
FACTORY_PAUSED
FACTORY_RESUMED
NONE
FILE_TRANSFER
RESERVE_SPACE
RELEASE_SPACE
FILE_COMPLETE
FILE_USED
FILE_REMOVED
class htcondor.FileTransferEventType

The event type for file transfer events; corresponds to FileTransferEventType in the C++ source.

The values of the enumeration are:

IN_QUEUED
IN_STARTED
IN_FINISHED
OUT_QUEUED
OUT_STARTED
OUT_FINISHED

HTCondor Configuration

htcondor.param = <htcondor.htcondor._Param object>

Provides dictionary-like access the HTCondor configuration.

An instance of _Param. Upon importing the htcondor module, the HTCondor configuration files are parsed and populate this dictionary-like object.

htcondor.reload_config() → None :

Reload the HTCondor configuration from disk.

class htcondor._Param

A dictionary-like object for the local HTCondor configuration; the keys and values of this object are the keys and values of the HTCondor configuration.

The get, setdefault, update, keys, items, and values methods of this class have the same semantics as a Python dictionary.

Writing to a _Param object will update the in-memory HTCondor configuration.

class htcondor.RemoteParam(ad)

The RemoteParam class provides a dictionary-like interface to the configuration of an HTCondor daemon. The get, setdefault, update, keys, items, and values methods of this class have the same semantics as a Python dictionary.

Parameters

ad (ClassAd) – An ad containing the location of the remote daemon.

refresh() → None :

Rebuilds the dictionary based on the current configuration of the daemon.

htcondor.platform() → str :

Returns the platform of HTCondor this module is running on.

htcondor.version() → str :

Returns the version of HTCondor this module is linked against.

HTCondor Logging

htcondor.enable_debug() → None :

Enable debugging output from HTCondor, where output is sent to stderr. The logging level is controlled by the TOOL_DEBUG parameter.

htcondor.enable_log() → None :

Enable debugging output from HTCondor, where output is sent to a file. The log level is controlled by the parameter TOOL_DEBUG, and the file used is controlled by TOOL_LOG.

htcondor.log(level, msg) → None :

Log a message using the HTCondor logging subsystem.

Parameters
  • level (LogLevel) – The log category and formatting indicator. Multiple LogLevel enum attributes may be OR’d together.

  • msg (str) – A message to log.

class htcondor.LogLevel

The log level attribute to use with log(). Note that HTCondor mixes both a class (debug, network, all) and the header format (Timestamp, PID, NoHeader) within this enumeration.

The values of the enumeration are:

Always
Audit
Config
DaemonCore
Error
FullDebug
Hostname
Job
Machine
Network
NoHeader
PID
Priv
Protocol
Security
Status
SubSecond
Terse
Timestamp
Verbose

Esoteric Functionality

htcondor.send_command(ad, dc, target) → None :

Send a command to an HTCondor daemon specified by a location ClassAd.

Parameters
  • ad (ClassAd) – Specifies the location of the daemon (typically, found by using Collector.locate()).

  • dc (DaemonCommands) – A command type

  • target (str) – An additional command to send to a daemon. Some commands require additional arguments; for example, sending DaemonOff to a condor_master requires one to specify which subsystem to turn off.

class htcondor.DaemonCommands

An enumeration of various state-changing commands that can be sent to a HTCondor daemon using send_command().

The values of the enumeration are:

DaemonOn
DaemonOff
DaemonOffFast
DaemonOffPeaceful
DaemonsOn
DaemonsOff
DaemonsOffFast
DaemonsOffPeaceful
OffFast
OffForce
OffGraceful
OffPeaceful
Reconfig
Restart
RestartPeacful
SetForceShutdown
SetPeacefulShutdown
htcondor.send_alive([ ad=None, pid=None, timeout=None) → None :

Send a keep alive message to an HTCondor daemon.

This is used when the python process is run as a child daemon under the condor_master.

Parameters
  • ad (ClassAd) – A ClassAd specifying the location of the daemon. This ad is typically found by using Collector.locate().

  • pid (int) – The process identifier for the keep alive. The default value of None uses the value from os.getpid().

  • timeout (int) – The number of seconds that this keep alive is valid. If a new keep alive is not received by the condor_master in time, then the process will be terminated. The default value is controlled by configuration variable NOT_RESPONDING_TIMEOUT.

htcondor.set_subsystem(subsystem, type=htcondor.htcondor.SubsystemType(16)) → None :

Set the subsystem name for the object.

The subsystem is primarily used for the parsing of the HTCondor configuration file.

Parameters
  • name (str) – The subsystem name.

  • daemon_type (SubsystemType) – The HTCondor daemon type. The default value of Auto infers the type from the name parameter.

class htcondor.SubsystemType

An enumeration of known subsystem names.

The values of the enumeration are:

Collector
Daemon
Dagman
GAHP
Job
Master
Negotiator
Schedd
Shadow
SharedPort
Startd
Starter
Submit
Tool

Exceptions

For backwards-compatibility, the exceptions in this module inherit from the built-in exceptions raised in earlier (pre-v8.9.9) versions.

class htcondor.HTCondorException

Never raised. The parent class of all exceptions raised by this module.

class htcondor.HTCondorEnumError

Raised when a value must be in an enumeration, but isn’t.

class htcondor.HTCondorInternalError

Raised when HTCondor encounters an internal error.

class htcondor.HTCondorIOError

Raised instead of IOError for backwards compatibility.

class htcondor.HTCondorLocateError

Raised when HTCondor cannot locate a daemon.

class htcondor.HTCondorReplyError

Raised when HTCondor received an invalid reply from a daemon, or the daemon’s reply indicated that it encountered an error.

class htcondor.HTCondorTypeError

Raised instead of TypeError for backwards compatibility.

class htcondor.HTCondorValueError

Raised instead of ValueError for backwards compatibility.

Thread Safety

Most of the htcondor module is protected by a lock that prevents multiple threads from executing locked functions at the same time. When two threads both want to call locked functions or methods, they will wait in line to execute them one at a time (the ordering between threads is not guaranteed beyond “first come first serve”). Examples of locked functions include: Schedd.query(), Submit.queue(), and Schedd.edit().

Threads that are not trying to execute locked htcondor functions will be allowed to proceed normally.

This locking may cause unexpected slowdowns when using htcondor from multiple threads simultaneously.