def monitor(pid, task_id, monitoring_hub_url, run_id, sleep_dur=<NUM_LIT:10>):
import psutil<EOL>radio = UDPRadio(monitoring_hub_url,<EOL>source_id=task_id)<EOL>simple = ["<STR_LIT>", '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT:name>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT:status>', '<STR_LIT:username>']<EOL>summable_values = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>pm = psutil.Process(pid)<EOL>pm.cpu_percent()<EOL>first_msg = True<EOL>while True:<EOL><INDENT>try:<EOL><INDENT>d = {"<STR_LIT>" + str(k): v for k, v in pm.as_dict().items() if k in simple}<EOL>d["<STR_LIT>"] = run_id<EOL>d["<STR_LIT>"] = task_id<EOL>d['<STR_LIT>'] = sleep_dur<EOL>d['<STR_LIT>'] = first_msg<EOL>d['<STR_LIT>'] = datetime.datetime.now()<EOL>children = pm.children(recursive=True)<EOL>d["<STR_LIT>"] = psutil.cpu_count()<EOL>d['<STR_LIT>'] = pm.memory_info().vms<EOL>d['<STR_LIT>'] = pm.memory_info().rss<EOL>d['<STR_LIT>'] = pm.cpu_times().user<EOL>d['<STR_LIT>'] = pm.cpu_times().system<EOL>d['<STR_LIT>'] = len(children)<EOL>try:<EOL><INDENT>d['<STR_LIT>'] = pm.io_counters().write_bytes<EOL>d['<STR_LIT>'] = pm.io_counters().read_bytes<EOL><DEDENT>except psutil._exceptions.AccessDenied:<EOL><INDENT>d['<STR_LIT>'] = <NUM_LIT:0><EOL>d['<STR_LIT>'] = <NUM_LIT:0><EOL><DEDENT>for child in children:<EOL><INDENT>for k, v in child.as_dict(attrs=summable_values).items():<EOL><INDENT>d['<STR_LIT>' + str(k)] += v<EOL><DEDENT>d['<STR_LIT>'] += child.cpu_times().user<EOL>d['<STR_LIT>'] += child.cpu_times().system<EOL>d['<STR_LIT>'] += child.memory_info().vms<EOL>d['<STR_LIT>'] += child.memory_info().rss<EOL>try:<EOL><INDENT>d['<STR_LIT>'] += child.io_counters().write_bytes<EOL>d['<STR_LIT>'] += child.io_counters().read_bytes<EOL><DEDENT>except psutil._exceptions.AccessDenied:<EOL><INDENT>d['<STR_LIT>'] += <NUM_LIT:0><EOL>d['<STR_LIT>'] += <NUM_LIT:0><EOL><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>radio.send(MessageType.TASK_INFO, task_id, d)<EOL>time.sleep(sleep_dur)<EOL>first_msg = False<EOL><DEDENT><DEDENT>
Internal
    Monitors the Parsl task's resources by pointing psutil to the task's pid and watching it and its children.