# 3.5。工作经理¶

## 3.5.1。重新运行预防¶

run()，就在实际工作执行之前，一份唯一的作业标识符（调用 哈希 ）计算出来。作业管理器存储先前运行的作业的所有散列，并检查您尝试执行的作业的哈希是否尚未存在。如果检测到这样的情况，则不会发生任何执行并使用先前作业的结果。以前的工作结果’S文件夹可以复制或链接到当前作业’s folder, based on link_files key in 以前的 job’s 设置.

It may happen that two jobs with exactly the same input and runscript files correspond to different jobs (for example if they rely on some external file that is supplied using relative path). Pay special attention to that. If you are experiencing problems (PLAMS sees two different jobs as the same one), disable the rerun prevention (config.jm.settings.hashing = None)

## 3.5.2。酸洗¶

The lifespan of all elements that are parts of PLAMS environment is limited to a single script. That means every script you run uses its own independent job manager, working folder or config settings. These objects are initialized at the beginning of the script with init() command and they cease to exist when the script ends. Also all settings adjustments (apart from those done by editing plams_defaults) are local just for one script.

Such a .dill file can be loaded in future scripts using load() function:

>>> oldjob = load('/home/user/science/plams.12345/myjob/myjob.dill')


Python酸洗机制遵循腌制物体中的引用。这意味着如果您尝试泡制的对象包含对另一个对象的引用（就像a Job 实例有一个参考 Results 实例），也保存了另一个对象。由于拆开后，没有“empty”对象中的引用。

myjob.something = some_big_and_clumsy_object_you_dont_want_to_pickle
myjob._dont_pickle = ['something'] #or myjob._dont_pickle.append('something')


That way big clumsy object will not be stored in the .dill file. After loading such a .dill file the value of myjob.something will simply be None.

_dont_pickle 是每个的属性 Job instance, initialized by the constructor to an empty list. It does not contain names of attributes that are always removed ( like  工作 manager, for example), only additional ones defined by the user (see Job.__getstate__)

A Results instance associated with a job is saved together with it. However, results do not contain all files produced by job execution, but only relative paths to them. For that reason the .dill file is not enough to fully restore the state if you want to process the results. All other files present in job’需要的文件夹 Results 实例可以与它们相关联。因此，如果要将以前的执行作业复制到另一个位置，请确保复制 整体 作业文件夹（包括子目录）。

## 3.5.3。重新启动崩溃的脚本¶

1. 如果你 wish to perform the restart run in a fresh, empty working folder, all you need to do is simply to import the contents of the previous working folder (from the crashed run) using -l flag:

plams myscript.plms
[17:28:40]  pl  working  文件夹 : /home/user/plams.12345
#[crashed]
#[correct myscript.plms]
plams -l plams.12345 myscript.plms
[17:35:44]  pl  working  文件夹 : /home/user/plams.23456

2. 如果你 would rather prefer to do an in-place restart and use the same working folder, you can use -r flag:

plams myscript.plms
[17:28:40]  pl  working  文件夹 : /home/user/plams.12345
#[crashed]
#[correct myscript.plms]
plams -r -f plams.12345 myscript.plms
[17:35:44]  pl  working  文件夹 : /home/user/plams.12345


In this case the master script will temporarily move all the contents of plams.12345 to plams.12345.res, import all the jobs from there and start a regular run in now empty plams.12345. At the end of the script plams.12345.res will be deleted.

## 3.5.4。 API.¶

•  文件夹  –工作文件夹名称。
•  小路  –使用工作文件夹的目录的绝对路径。
• workdir – the absolute path to the working folder ( 小路 /folder ）。
• 设置 – a Settings 此工作管理器的实例（见下文）。
•  工作 s –使用此实例管理的所有作业列表（按顺序排列） run() calls).
• names –一个关于作业名称的字典。对于每个名称，存储整数值，指示已运行该名称的作业数量。
•  哈希 es –用作作业的哈希表的字典。

 小路  文件夹  can be adjusted with constructor arguments 小路 文件夹 . If not supplied, Python current working directory and string plams. appended with PID of the current process are used.

设置 属性直接设置为值 设置 参数（与他们被复制的其他类别不同），它应该是一个 Settings 使用以下键的实例：

•  哈希 ing –选择散列方法（见 重新运行预防 ）。
• counter_len –在名称冲突的情况下，向作业名称附加到作业名称的长度。
• remove_empty_directories – if True, all empty subdirectories of the working folder are removed on finish().
_register_name( 工作 )[来源]

_register( 工作 )[来源]

_check_hash( 工作 )[来源]

load_job(文件名)[来源]

remove_job( 工作 )[来源]

_clean()[来源]

Clean all registered jobs according to their save parameter in their 设置. If remove_empty_directories is True, traverse the working directory and delete all empty subdirectories.