id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
29,800 | binux/pyspider | pyspider/scheduler/scheduler.py | Scheduler._check_cronjob | def _check_cronjob(self):
"""Check projects cronjob tick, return True when a new tick is sended"""
now = time.time()
self._last_tick = int(self._last_tick)
if now - self._last_tick < 1:
return False
self._last_tick += 1
for project in itervalues(self.projects)... | python | def _check_cronjob(self):
"""Check projects cronjob tick, return True when a new tick is sended"""
now = time.time()
self._last_tick = int(self._last_tick)
if now - self._last_tick < 1:
return False
self._last_tick += 1
for project in itervalues(self.projects)... | [
"def",
"_check_cronjob",
"(",
"self",
")",
":",
"now",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"_last_tick",
"=",
"int",
"(",
"self",
".",
"_last_tick",
")",
"if",
"now",
"-",
"self",
".",
"_last_tick",
"<",
"1",
":",
"return",
"False",
"s... | Check projects cronjob tick, return True when a new tick is sended | [
"Check",
"projects",
"cronjob",
"tick",
"return",
"True",
"when",
"a",
"new",
"tick",
"is",
"sended"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L419-L449 |
29,801 | binux/pyspider | pyspider/scheduler/scheduler.py | Scheduler._check_select | def _check_select(self):
'''Select task to fetch & process'''
while self._send_buffer:
_task = self._send_buffer.pop()
try:
# use force=False here to prevent automatic send_buffer append and get exception
self.send_task(_task, False)
ex... | python | def _check_select(self):
'''Select task to fetch & process'''
while self._send_buffer:
_task = self._send_buffer.pop()
try:
# use force=False here to prevent automatic send_buffer append and get exception
self.send_task(_task, False)
ex... | [
"def",
"_check_select",
"(",
"self",
")",
":",
"while",
"self",
".",
"_send_buffer",
":",
"_task",
"=",
"self",
".",
"_send_buffer",
".",
"pop",
"(",
")",
"try",
":",
"# use force=False here to prevent automatic send_buffer append and get exception",
"self",
".",
"s... | Select task to fetch & process | [
"Select",
"task",
"to",
"fetch",
"&",
"process"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L463-L566 |
29,802 | binux/pyspider | pyspider/scheduler/scheduler.py | Scheduler._try_dump_cnt | def _try_dump_cnt(self):
'''Dump counters every 60 seconds'''
now = time.time()
if now - self._last_dump_cnt > 60:
self._last_dump_cnt = now
self._dump_cnt()
self._print_counter_log() | python | def _try_dump_cnt(self):
'''Dump counters every 60 seconds'''
now = time.time()
if now - self._last_dump_cnt > 60:
self._last_dump_cnt = now
self._dump_cnt()
self._print_counter_log() | [
"def",
"_try_dump_cnt",
"(",
"self",
")",
":",
"now",
"=",
"time",
".",
"time",
"(",
")",
"if",
"now",
"-",
"self",
".",
"_last_dump_cnt",
">",
"60",
":",
"self",
".",
"_last_dump_cnt",
"=",
"now",
"self",
".",
"_dump_cnt",
"(",
")",
"self",
".",
"... | Dump counters every 60 seconds | [
"Dump",
"counters",
"every",
"60",
"seconds"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L622-L628 |
29,803 | binux/pyspider | pyspider/scheduler/scheduler.py | Scheduler._check_delete | def _check_delete(self):
'''Check project delete'''
now = time.time()
for project in list(itervalues(self.projects)):
if project.db_status != 'STOP':
continue
if now - project.updatetime < self.DELETE_TIME:
continue
if 'delete' ... | python | def _check_delete(self):
'''Check project delete'''
now = time.time()
for project in list(itervalues(self.projects)):
if project.db_status != 'STOP':
continue
if now - project.updatetime < self.DELETE_TIME:
continue
if 'delete' ... | [
"def",
"_check_delete",
"(",
"self",
")",
":",
"now",
"=",
"time",
".",
"time",
"(",
")",
"for",
"project",
"in",
"list",
"(",
"itervalues",
"(",
"self",
".",
"projects",
")",
")",
":",
"if",
"project",
".",
"db_status",
"!=",
"'STOP'",
":",
"continu... | Check project delete | [
"Check",
"project",
"delete"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L630-L648 |
29,804 | binux/pyspider | pyspider/scheduler/scheduler.py | Scheduler.quit | def quit(self):
'''Set quit signal'''
self._quit = True
# stop xmlrpc server
if hasattr(self, 'xmlrpc_server'):
self.xmlrpc_ioloop.add_callback(self.xmlrpc_server.stop)
self.xmlrpc_ioloop.add_callback(self.xmlrpc_ioloop.stop) | python | def quit(self):
'''Set quit signal'''
self._quit = True
# stop xmlrpc server
if hasattr(self, 'xmlrpc_server'):
self.xmlrpc_ioloop.add_callback(self.xmlrpc_server.stop)
self.xmlrpc_ioloop.add_callback(self.xmlrpc_ioloop.stop) | [
"def",
"quit",
"(",
"self",
")",
":",
"self",
".",
"_quit",
"=",
"True",
"# stop xmlrpc server",
"if",
"hasattr",
"(",
"self",
",",
"'xmlrpc_server'",
")",
":",
"self",
".",
"xmlrpc_ioloop",
".",
"add_callback",
"(",
"self",
".",
"xmlrpc_server",
".",
"sto... | Set quit signal | [
"Set",
"quit",
"signal"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L653-L659 |
29,805 | binux/pyspider | pyspider/scheduler/scheduler.py | Scheduler.run_once | def run_once(self):
'''comsume queues and feed tasks to fetcher, once'''
self._update_projects()
self._check_task_done()
self._check_request()
while self._check_cronjob():
pass
self._check_select()
self._check_delete()
self._try_dump_cnt() | python | def run_once(self):
'''comsume queues and feed tasks to fetcher, once'''
self._update_projects()
self._check_task_done()
self._check_request()
while self._check_cronjob():
pass
self._check_select()
self._check_delete()
self._try_dump_cnt() | [
"def",
"run_once",
"(",
"self",
")",
":",
"self",
".",
"_update_projects",
"(",
")",
"self",
".",
"_check_task_done",
"(",
")",
"self",
".",
"_check_request",
"(",
")",
"while",
"self",
".",
"_check_cronjob",
"(",
")",
":",
"pass",
"self",
".",
"_check_s... | comsume queues and feed tasks to fetcher, once | [
"comsume",
"queues",
"and",
"feed",
"tasks",
"to",
"fetcher",
"once"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L661-L671 |
29,806 | binux/pyspider | pyspider/scheduler/scheduler.py | Scheduler.run | def run(self):
'''Start scheduler loop'''
logger.info("scheduler starting...")
while not self._quit:
try:
time.sleep(self.LOOP_INTERVAL)
self.run_once()
self._exceptions = 0
except KeyboardInterrupt:
break
... | python | def run(self):
'''Start scheduler loop'''
logger.info("scheduler starting...")
while not self._quit:
try:
time.sleep(self.LOOP_INTERVAL)
self.run_once()
self._exceptions = 0
except KeyboardInterrupt:
break
... | [
"def",
"run",
"(",
"self",
")",
":",
"logger",
".",
"info",
"(",
"\"scheduler starting...\"",
")",
"while",
"not",
"self",
".",
"_quit",
":",
"try",
":",
"time",
".",
"sleep",
"(",
"self",
".",
"LOOP_INTERVAL",
")",
"self",
".",
"run_once",
"(",
")",
... | Start scheduler loop | [
"Start",
"scheduler",
"loop"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L673-L692 |
29,807 | binux/pyspider | pyspider/scheduler/scheduler.py | Scheduler.on_new_request | def on_new_request(self, task):
'''Called when a new request is arrived'''
task['status'] = self.taskdb.ACTIVE
self.insert_task(task)
self.put_task(task)
project = task['project']
self._cnt['5m'].event((project, 'pending'), +1)
self._cnt['1h'].event((project, 'pe... | python | def on_new_request(self, task):
'''Called when a new request is arrived'''
task['status'] = self.taskdb.ACTIVE
self.insert_task(task)
self.put_task(task)
project = task['project']
self._cnt['5m'].event((project, 'pending'), +1)
self._cnt['1h'].event((project, 'pe... | [
"def",
"on_new_request",
"(",
"self",
",",
"task",
")",
":",
"task",
"[",
"'status'",
"]",
"=",
"self",
".",
"taskdb",
".",
"ACTIVE",
"self",
".",
"insert_task",
"(",
"task",
")",
"self",
".",
"put_task",
"(",
"task",
")",
"project",
"=",
"task",
"["... | Called when a new request is arrived | [
"Called",
"when",
"a",
"new",
"request",
"is",
"arrived"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L825-L837 |
29,808 | binux/pyspider | pyspider/scheduler/scheduler.py | Scheduler.on_old_request | def on_old_request(self, task, old_task):
'''Called when a crawled task is arrived'''
now = time.time()
_schedule = task.get('schedule', self.default_schedule)
old_schedule = old_task.get('schedule', {})
if _schedule.get('force_update') and self.projects[task['project']].task_q... | python | def on_old_request(self, task, old_task):
'''Called when a crawled task is arrived'''
now = time.time()
_schedule = task.get('schedule', self.default_schedule)
old_schedule = old_task.get('schedule', {})
if _schedule.get('force_update') and self.projects[task['project']].task_q... | [
"def",
"on_old_request",
"(",
"self",
",",
"task",
",",
"old_task",
")",
":",
"now",
"=",
"time",
".",
"time",
"(",
")",
"_schedule",
"=",
"task",
".",
"get",
"(",
"'schedule'",
",",
"self",
".",
"default_schedule",
")",
"old_schedule",
"=",
"old_task",
... | Called when a crawled task is arrived | [
"Called",
"when",
"a",
"crawled",
"task",
"is",
"arrived"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L839-L887 |
29,809 | binux/pyspider | pyspider/scheduler/scheduler.py | Scheduler.on_task_status | def on_task_status(self, task):
'''Called when a status pack is arrived'''
try:
procesok = task['track']['process']['ok']
if not self.projects[task['project']].task_queue.done(task['taskid']):
logging.error('not processing pack: %(project)s:%(taskid)s %(url)s', ta... | python | def on_task_status(self, task):
'''Called when a status pack is arrived'''
try:
procesok = task['track']['process']['ok']
if not self.projects[task['project']].task_queue.done(task['taskid']):
logging.error('not processing pack: %(project)s:%(taskid)s %(url)s', ta... | [
"def",
"on_task_status",
"(",
"self",
",",
"task",
")",
":",
"try",
":",
"procesok",
"=",
"task",
"[",
"'track'",
"]",
"[",
"'process'",
"]",
"[",
"'ok'",
"]",
"if",
"not",
"self",
".",
"projects",
"[",
"task",
"[",
"'project'",
"]",
"]",
".",
"tas... | Called when a status pack is arrived | [
"Called",
"when",
"a",
"status",
"pack",
"is",
"arrived"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L889-L912 |
29,810 | binux/pyspider | pyspider/scheduler/scheduler.py | Scheduler.on_task_done | def on_task_done(self, task):
'''Called when a task is done and success, called by `on_task_status`'''
task['status'] = self.taskdb.SUCCESS
task['lastcrawltime'] = time.time()
if 'schedule' in task:
if task['schedule'].get('auto_recrawl') and 'age' in task['schedule']:
... | python | def on_task_done(self, task):
'''Called when a task is done and success, called by `on_task_status`'''
task['status'] = self.taskdb.SUCCESS
task['lastcrawltime'] = time.time()
if 'schedule' in task:
if task['schedule'].get('auto_recrawl') and 'age' in task['schedule']:
... | [
"def",
"on_task_done",
"(",
"self",
",",
"task",
")",
":",
"task",
"[",
"'status'",
"]",
"=",
"self",
".",
"taskdb",
".",
"SUCCESS",
"task",
"[",
"'lastcrawltime'",
"]",
"=",
"time",
".",
"time",
"(",
")",
"if",
"'schedule'",
"in",
"task",
":",
"if",... | Called when a task is done and success, called by `on_task_status` | [
"Called",
"when",
"a",
"task",
"is",
"done",
"and",
"success",
"called",
"by",
"on_task_status"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L914-L935 |
29,811 | binux/pyspider | pyspider/scheduler/scheduler.py | Scheduler.on_task_failed | def on_task_failed(self, task):
'''Called when a task is failed, called by `on_task_status`'''
if 'schedule' not in task:
old_task = self.taskdb.get_task(task['project'], task['taskid'], fields=['schedule'])
if old_task is None:
logging.error('unknown status pack... | python | def on_task_failed(self, task):
'''Called when a task is failed, called by `on_task_status`'''
if 'schedule' not in task:
old_task = self.taskdb.get_task(task['project'], task['taskid'], fields=['schedule'])
if old_task is None:
logging.error('unknown status pack... | [
"def",
"on_task_failed",
"(",
"self",
",",
"task",
")",
":",
"if",
"'schedule'",
"not",
"in",
"task",
":",
"old_task",
"=",
"self",
".",
"taskdb",
".",
"get_task",
"(",
"task",
"[",
"'project'",
"]",
",",
"task",
"[",
"'taskid'",
"]",
",",
"fields",
... | Called when a task is failed, called by `on_task_status` | [
"Called",
"when",
"a",
"task",
"is",
"failed",
"called",
"by",
"on_task_status"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L937-L988 |
29,812 | binux/pyspider | pyspider/scheduler/scheduler.py | Scheduler.on_select_task | def on_select_task(self, task):
'''Called when a task is selected to fetch & process'''
# inject informations about project
logger.info('select %(project)s:%(taskid)s %(url)s', task)
project_info = self.projects.get(task['project'])
assert project_info, 'no such project'
... | python | def on_select_task(self, task):
'''Called when a task is selected to fetch & process'''
# inject informations about project
logger.info('select %(project)s:%(taskid)s %(url)s', task)
project_info = self.projects.get(task['project'])
assert project_info, 'no such project'
... | [
"def",
"on_select_task",
"(",
"self",
",",
"task",
")",
":",
"# inject informations about project",
"logger",
".",
"info",
"(",
"'select %(project)s:%(taskid)s %(url)s'",
",",
"task",
")",
"project_info",
"=",
"self",
".",
"projects",
".",
"get",
"(",
"task",
"[",... | Called when a task is selected to fetch & process | [
"Called",
"when",
"a",
"task",
"is",
"selected",
"to",
"fetch",
"&",
"process"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L990-L1008 |
29,813 | binux/pyspider | pyspider/scheduler/scheduler.py | OneScheduler._check_select | def _check_select(self):
"""
interactive mode of select tasks
"""
if not self.interactive:
return super(OneScheduler, self)._check_select()
# waiting for running tasks
if self.running_task > 0:
return
is_crawled = []
def run(proj... | python | def _check_select(self):
"""
interactive mode of select tasks
"""
if not self.interactive:
return super(OneScheduler, self)._check_select()
# waiting for running tasks
if self.running_task > 0:
return
is_crawled = []
def run(proj... | [
"def",
"_check_select",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"interactive",
":",
"return",
"super",
"(",
"OneScheduler",
",",
"self",
")",
".",
"_check_select",
"(",
")",
"# waiting for running tasks",
"if",
"self",
".",
"running_task",
">",
"0",... | interactive mode of select tasks | [
"interactive",
"mode",
"of",
"select",
"tasks"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L1022-L1104 |
29,814 | binux/pyspider | pyspider/scheduler/scheduler.py | OneScheduler.on_task_status | def on_task_status(self, task):
"""Ignore not processing error in interactive mode"""
if not self.interactive:
super(OneScheduler, self).on_task_status(task)
try:
procesok = task['track']['process']['ok']
except KeyError as e:
logger.error("Bad status... | python | def on_task_status(self, task):
"""Ignore not processing error in interactive mode"""
if not self.interactive:
super(OneScheduler, self).on_task_status(task)
try:
procesok = task['track']['process']['ok']
except KeyError as e:
logger.error("Bad status... | [
"def",
"on_task_status",
"(",
"self",
",",
"task",
")",
":",
"if",
"not",
"self",
".",
"interactive",
":",
"super",
"(",
"OneScheduler",
",",
"self",
")",
".",
"on_task_status",
"(",
"task",
")",
"try",
":",
"procesok",
"=",
"task",
"[",
"'track'",
"]"... | Ignore not processing error in interactive mode | [
"Ignore",
"not",
"processing",
"error",
"in",
"interactive",
"mode"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L1112-L1134 |
29,815 | binux/pyspider | pyspider/processor/project_module.py | ProjectManager.build_module | def build_module(project, env=None):
'''Build project script as module'''
from pyspider.libs import base_handler
assert 'name' in project, 'need name of project'
assert 'script' in project, 'need script of project'
if env is None:
env = {}
# fix for old non-p... | python | def build_module(project, env=None):
'''Build project script as module'''
from pyspider.libs import base_handler
assert 'name' in project, 'need name of project'
assert 'script' in project, 'need script of project'
if env is None:
env = {}
# fix for old non-p... | [
"def",
"build_module",
"(",
"project",
",",
"env",
"=",
"None",
")",
":",
"from",
"pyspider",
".",
"libs",
"import",
"base_handler",
"assert",
"'name'",
"in",
"project",
",",
"'need name of project'",
"assert",
"'script'",
"in",
"project",
",",
"'need script of ... | Build project script as module | [
"Build",
"project",
"script",
"as",
"module"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/processor/project_module.py#L32-L87 |
29,816 | binux/pyspider | pyspider/processor/project_module.py | ProjectManager._need_update | def _need_update(self, project_name, updatetime=None, md5sum=None):
'''Check if project_name need update'''
if project_name not in self.projects:
return True
elif md5sum and md5sum != self.projects[project_name]['info'].get('md5sum'):
return True
elif updatetime a... | python | def _need_update(self, project_name, updatetime=None, md5sum=None):
'''Check if project_name need update'''
if project_name not in self.projects:
return True
elif md5sum and md5sum != self.projects[project_name]['info'].get('md5sum'):
return True
elif updatetime a... | [
"def",
"_need_update",
"(",
"self",
",",
"project_name",
",",
"updatetime",
"=",
"None",
",",
"md5sum",
"=",
"None",
")",
":",
"if",
"project_name",
"not",
"in",
"self",
".",
"projects",
":",
"return",
"True",
"elif",
"md5sum",
"and",
"md5sum",
"!=",
"se... | Check if project_name need update | [
"Check",
"if",
"project_name",
"need",
"update"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/processor/project_module.py#L96-L106 |
29,817 | binux/pyspider | pyspider/processor/project_module.py | ProjectManager._check_projects | def _check_projects(self):
'''Check projects by last update time'''
for project in self.projectdb.check_update(self.last_check_projects,
['name', 'updatetime']):
if project['name'] not in self.projects:
continue
i... | python | def _check_projects(self):
'''Check projects by last update time'''
for project in self.projectdb.check_update(self.last_check_projects,
['name', 'updatetime']):
if project['name'] not in self.projects:
continue
i... | [
"def",
"_check_projects",
"(",
"self",
")",
":",
"for",
"project",
"in",
"self",
".",
"projectdb",
".",
"check_update",
"(",
"self",
".",
"last_check_projects",
",",
"[",
"'name'",
",",
"'updatetime'",
"]",
")",
":",
"if",
"project",
"[",
"'name'",
"]",
... | Check projects by last update time | [
"Check",
"projects",
"by",
"last",
"update",
"time"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/processor/project_module.py#L108-L116 |
29,818 | binux/pyspider | pyspider/processor/project_module.py | ProjectManager._update_project | def _update_project(self, project_name):
'''Update one project from database'''
project = self.projectdb.get(project_name)
if not project:
return None
return self._load_project(project) | python | def _update_project(self, project_name):
'''Update one project from database'''
project = self.projectdb.get(project_name)
if not project:
return None
return self._load_project(project) | [
"def",
"_update_project",
"(",
"self",
",",
"project_name",
")",
":",
"project",
"=",
"self",
".",
"projectdb",
".",
"get",
"(",
"project_name",
")",
"if",
"not",
"project",
":",
"return",
"None",
"return",
"self",
".",
"_load_project",
"(",
"project",
")"... | Update one project from database | [
"Update",
"one",
"project",
"from",
"database"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/processor/project_module.py#L118-L123 |
29,819 | binux/pyspider | pyspider/processor/project_module.py | ProjectManager._load_project | def _load_project(self, project):
'''Load project into self.projects from project info dict'''
try:
project['md5sum'] = utils.md5string(project['script'])
ret = self.build_module(project, self.env)
self.projects[project['name']] = ret
except Exception as e:
... | python | def _load_project(self, project):
'''Load project into self.projects from project info dict'''
try:
project['md5sum'] = utils.md5string(project['script'])
ret = self.build_module(project, self.env)
self.projects[project['name']] = ret
except Exception as e:
... | [
"def",
"_load_project",
"(",
"self",
",",
"project",
")",
":",
"try",
":",
"project",
"[",
"'md5sum'",
"]",
"=",
"utils",
".",
"md5string",
"(",
"project",
"[",
"'script'",
"]",
")",
"ret",
"=",
"self",
".",
"build_module",
"(",
"project",
",",
"self",... | Load project into self.projects from project info dict | [
"Load",
"project",
"into",
"self",
".",
"projects",
"from",
"project",
"info",
"dict"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/processor/project_module.py#L125-L146 |
29,820 | binux/pyspider | pyspider/processor/project_module.py | ProjectManager.get | def get(self, project_name, updatetime=None, md5sum=None):
'''get project data object, return None if not exists'''
if time.time() - self.last_check_projects > self.CHECK_PROJECTS_INTERVAL:
self._check_projects()
if self._need_update(project_name, updatetime, md5sum):
sel... | python | def get(self, project_name, updatetime=None, md5sum=None):
'''get project data object, return None if not exists'''
if time.time() - self.last_check_projects > self.CHECK_PROJECTS_INTERVAL:
self._check_projects()
if self._need_update(project_name, updatetime, md5sum):
sel... | [
"def",
"get",
"(",
"self",
",",
"project_name",
",",
"updatetime",
"=",
"None",
",",
"md5sum",
"=",
"None",
")",
":",
"if",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"last_check_projects",
">",
"self",
".",
"CHECK_PROJECTS_INTERVAL",
":",
"self",
... | get project data object, return None if not exists | [
"get",
"project",
"data",
"object",
"return",
"None",
"if",
"not",
"exists"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/processor/project_module.py#L148-L154 |
29,821 | binux/pyspider | pyspider/fetcher/cookie_utils.py | MockResponse.get_all | def get_all(self, name, default=None):
"""make cookie python 3 version use this instead of getheaders"""
if default is None:
default = []
return self._headers.get_list(name) or default | python | def get_all(self, name, default=None):
"""make cookie python 3 version use this instead of getheaders"""
if default is None:
default = []
return self._headers.get_list(name) or default | [
"def",
"get_all",
"(",
"self",
",",
"name",
",",
"default",
"=",
"None",
")",
":",
"if",
"default",
"is",
"None",
":",
"default",
"=",
"[",
"]",
"return",
"self",
".",
"_headers",
".",
"get_list",
"(",
"name",
")",
"or",
"default"
] | make cookie python 3 version use this instead of getheaders | [
"make",
"cookie",
"python",
"3",
"version",
"use",
"this",
"instead",
"of",
"getheaders"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/fetcher/cookie_utils.py#L23-L27 |
29,822 | binux/pyspider | pyspider/database/elasticsearch/taskdb.py | TaskDB.refresh | def refresh(self):
"""
Explicitly refresh one or more index, making all operations
performed since the last refresh available for search.
"""
self._changed = False
self.es.indices.refresh(index=self.index) | python | def refresh(self):
"""
Explicitly refresh one or more index, making all operations
performed since the last refresh available for search.
"""
self._changed = False
self.es.indices.refresh(index=self.index) | [
"def",
"refresh",
"(",
"self",
")",
":",
"self",
".",
"_changed",
"=",
"False",
"self",
".",
"es",
".",
"indices",
".",
"refresh",
"(",
"index",
"=",
"self",
".",
"index",
")"
] | Explicitly refresh one or more index, making all operations
performed since the last refresh available for search. | [
"Explicitly",
"refresh",
"one",
"or",
"more",
"index",
"making",
"all",
"operations",
"performed",
"since",
"the",
"last",
"refresh",
"available",
"for",
"search",
"."
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/database/elasticsearch/taskdb.py#L119-L125 |
29,823 | binux/pyspider | pyspider/fetcher/tornado_fetcher.py | Fetcher.send_result | def send_result(self, type, task, result):
'''Send fetch result to processor'''
if self.outqueue:
try:
self.outqueue.put((task, result))
except Exception as e:
logger.exception(e) | python | def send_result(self, type, task, result):
'''Send fetch result to processor'''
if self.outqueue:
try:
self.outqueue.put((task, result))
except Exception as e:
logger.exception(e) | [
"def",
"send_result",
"(",
"self",
",",
"type",
",",
"task",
",",
"result",
")",
":",
"if",
"self",
".",
"outqueue",
":",
"try",
":",
"self",
".",
"outqueue",
".",
"put",
"(",
"(",
"task",
",",
"result",
")",
")",
"except",
"Exception",
"as",
"e",
... | Send fetch result to processor | [
"Send",
"fetch",
"result",
"to",
"processor"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/fetcher/tornado_fetcher.py#L108-L114 |
29,824 | binux/pyspider | pyspider/fetcher/tornado_fetcher.py | Fetcher.async_fetch | def async_fetch(self, task, callback=None):
'''Do one fetch'''
url = task.get('url', 'data:,')
if callback is None:
callback = self.send_result
type = 'None'
start_time = time.time()
try:
if url.startswith('data:'):
type = 'data'
... | python | def async_fetch(self, task, callback=None):
'''Do one fetch'''
url = task.get('url', 'data:,')
if callback is None:
callback = self.send_result
type = 'None'
start_time = time.time()
try:
if url.startswith('data:'):
type = 'data'
... | [
"def",
"async_fetch",
"(",
"self",
",",
"task",
",",
"callback",
"=",
"None",
")",
":",
"url",
"=",
"task",
".",
"get",
"(",
"'url'",
",",
"'data:,'",
")",
"if",
"callback",
"is",
"None",
":",
"callback",
"=",
"self",
".",
"send_result",
"type",
"=",... | Do one fetch | [
"Do",
"one",
"fetch"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/fetcher/tornado_fetcher.py#L123-L153 |
29,825 | binux/pyspider | pyspider/fetcher/tornado_fetcher.py | Fetcher.sync_fetch | def sync_fetch(self, task):
'''Synchronization fetch, usually used in xmlrpc thread'''
if not self._running:
return self.ioloop.run_sync(functools.partial(self.async_fetch, task, lambda t, _, r: True))
wait_result = threading.Condition()
_result = {}
def callback(ty... | python | def sync_fetch(self, task):
'''Synchronization fetch, usually used in xmlrpc thread'''
if not self._running:
return self.ioloop.run_sync(functools.partial(self.async_fetch, task, lambda t, _, r: True))
wait_result = threading.Condition()
_result = {}
def callback(ty... | [
"def",
"sync_fetch",
"(",
"self",
",",
"task",
")",
":",
"if",
"not",
"self",
".",
"_running",
":",
"return",
"self",
".",
"ioloop",
".",
"run_sync",
"(",
"functools",
".",
"partial",
"(",
"self",
".",
"async_fetch",
",",
"task",
",",
"lambda",
"t",
... | Synchronization fetch, usually used in xmlrpc thread | [
"Synchronization",
"fetch",
"usually",
"used",
"in",
"xmlrpc",
"thread"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/fetcher/tornado_fetcher.py#L155-L176 |
29,826 | binux/pyspider | pyspider/fetcher/tornado_fetcher.py | Fetcher.data_fetch | def data_fetch(self, url, task):
'''A fake fetcher for dataurl'''
self.on_fetch('data', task)
result = {}
result['orig_url'] = url
result['content'] = dataurl.decode(url)
result['headers'] = {}
result['status_code'] = 200
result['url'] = url
result... | python | def data_fetch(self, url, task):
'''A fake fetcher for dataurl'''
self.on_fetch('data', task)
result = {}
result['orig_url'] = url
result['content'] = dataurl.decode(url)
result['headers'] = {}
result['status_code'] = 200
result['url'] = url
result... | [
"def",
"data_fetch",
"(",
"self",
",",
"url",
",",
"task",
")",
":",
"self",
".",
"on_fetch",
"(",
"'data'",
",",
"task",
")",
"result",
"=",
"{",
"}",
"result",
"[",
"'orig_url'",
"]",
"=",
"url",
"result",
"[",
"'content'",
"]",
"=",
"dataurl",
"... | A fake fetcher for dataurl | [
"A",
"fake",
"fetcher",
"for",
"dataurl"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/fetcher/tornado_fetcher.py#L178-L200 |
29,827 | binux/pyspider | pyspider/fetcher/tornado_fetcher.py | Fetcher.xmlrpc_run | def xmlrpc_run(self, port=24444, bind='127.0.0.1', logRequests=False):
'''Run xmlrpc server'''
import umsgpack
from pyspider.libs.wsgi_xmlrpc import WSGIXMLRPCApplication
try:
from xmlrpc.client import Binary
except ImportError:
from xmlrpclib import Binar... | python | def xmlrpc_run(self, port=24444, bind='127.0.0.1', logRequests=False):
'''Run xmlrpc server'''
import umsgpack
from pyspider.libs.wsgi_xmlrpc import WSGIXMLRPCApplication
try:
from xmlrpc.client import Binary
except ImportError:
from xmlrpclib import Binar... | [
"def",
"xmlrpc_run",
"(",
"self",
",",
"port",
"=",
"24444",
",",
"bind",
"=",
"'127.0.0.1'",
",",
"logRequests",
"=",
"False",
")",
":",
"import",
"umsgpack",
"from",
"pyspider",
".",
"libs",
".",
"wsgi_xmlrpc",
"import",
"WSGIXMLRPCApplication",
"try",
":"... | Run xmlrpc server | [
"Run",
"xmlrpc",
"server"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/fetcher/tornado_fetcher.py#L792-L825 |
29,828 | binux/pyspider | pyspider/fetcher/tornado_fetcher.py | Fetcher.on_result | def on_result(self, type, task, result):
'''Called after task fetched'''
status_code = result.get('status_code', 599)
if status_code != 599:
status_code = (int(status_code) / 100 * 100)
self._cnt['5m'].event((task.get('project'), status_code), +1)
self._cnt['1h'].even... | python | def on_result(self, type, task, result):
'''Called after task fetched'''
status_code = result.get('status_code', 599)
if status_code != 599:
status_code = (int(status_code) / 100 * 100)
self._cnt['5m'].event((task.get('project'), status_code), +1)
self._cnt['1h'].even... | [
"def",
"on_result",
"(",
"self",
",",
"type",
",",
"task",
",",
"result",
")",
":",
"status_code",
"=",
"result",
".",
"get",
"(",
"'status_code'",
",",
"599",
")",
"if",
"status_code",
"!=",
"599",
":",
"status_code",
"=",
"(",
"int",
"(",
"status_cod... | Called after task fetched | [
"Called",
"after",
"task",
"fetched"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/fetcher/tornado_fetcher.py#L831-L846 |
29,829 | binux/pyspider | pyspider/libs/counter.py | CounterManager.value | def value(self, key, value=1):
"""Set value of a counter by counter key"""
if isinstance(key, six.string_types):
key = (key, )
# assert all(isinstance(k, six.string_types) for k in key)
assert isinstance(key, tuple), "event key type error"
if key not in self.counters:... | python | def value(self, key, value=1):
"""Set value of a counter by counter key"""
if isinstance(key, six.string_types):
key = (key, )
# assert all(isinstance(k, six.string_types) for k in key)
assert isinstance(key, tuple), "event key type error"
if key not in self.counters:... | [
"def",
"value",
"(",
"self",
",",
"key",
",",
"value",
"=",
"1",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"six",
".",
"string_types",
")",
":",
"key",
"=",
"(",
"key",
",",
")",
"# assert all(isinstance(k, six.string_types) for k in key)",
"assert",
... | Set value of a counter by counter key | [
"Set",
"value",
"of",
"a",
"counter",
"by",
"counter",
"key"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/libs/counter.py#L355-L364 |
29,830 | binux/pyspider | pyspider/libs/counter.py | CounterManager.trim | def trim(self):
"""Clear not used counters"""
for key, value in list(iteritems(self.counters)):
if value.empty():
del self.counters[key] | python | def trim(self):
"""Clear not used counters"""
for key, value in list(iteritems(self.counters)):
if value.empty():
del self.counters[key] | [
"def",
"trim",
"(",
"self",
")",
":",
"for",
"key",
",",
"value",
"in",
"list",
"(",
"iteritems",
"(",
"self",
".",
"counters",
")",
")",
":",
"if",
"value",
".",
"empty",
"(",
")",
":",
"del",
"self",
".",
"counters",
"[",
"key",
"]"
] | Clear not used counters | [
"Clear",
"not",
"used",
"counters"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/libs/counter.py#L366-L370 |
29,831 | binux/pyspider | pyspider/libs/counter.py | CounterManager.load | def load(self, filename):
"""Load counters to file"""
try:
with open(filename, 'rb') as fp:
self.counters = cPickle.load(fp)
except:
logging.debug("can't load counter from file: %s", filename)
return False
return True | python | def load(self, filename):
"""Load counters to file"""
try:
with open(filename, 'rb') as fp:
self.counters = cPickle.load(fp)
except:
logging.debug("can't load counter from file: %s", filename)
return False
return True | [
"def",
"load",
"(",
"self",
",",
"filename",
")",
":",
"try",
":",
"with",
"open",
"(",
"filename",
",",
"'rb'",
")",
"as",
"fp",
":",
"self",
".",
"counters",
"=",
"cPickle",
".",
"load",
"(",
"fp",
")",
"except",
":",
"logging",
".",
"debug",
"... | Load counters to file | [
"Load",
"counters",
"to",
"file"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/libs/counter.py#L433-L441 |
29,832 | binux/pyspider | pyspider/run.py | scheduler | def scheduler(ctx, xmlrpc, xmlrpc_host, xmlrpc_port,
inqueue_limit, delete_time, active_tasks, loop_limit, fail_pause_num,
scheduler_cls, threads, get_object=False):
"""
Run Scheduler, only one scheduler is allowed.
"""
g = ctx.obj
Scheduler = load_cls(None, None, schedul... | python | def scheduler(ctx, xmlrpc, xmlrpc_host, xmlrpc_port,
inqueue_limit, delete_time, active_tasks, loop_limit, fail_pause_num,
scheduler_cls, threads, get_object=False):
"""
Run Scheduler, only one scheduler is allowed.
"""
g = ctx.obj
Scheduler = load_cls(None, None, schedul... | [
"def",
"scheduler",
"(",
"ctx",
",",
"xmlrpc",
",",
"xmlrpc_host",
",",
"xmlrpc_port",
",",
"inqueue_limit",
",",
"delete_time",
",",
"active_tasks",
",",
"loop_limit",
",",
"fail_pause_num",
",",
"scheduler_cls",
",",
"threads",
",",
"get_object",
"=",
"False",... | Run Scheduler, only one scheduler is allowed. | [
"Run",
"Scheduler",
"only",
"one",
"scheduler",
"is",
"allowed",
"."
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/run.py#L192-L220 |
29,833 | binux/pyspider | pyspider/run.py | fetcher | def fetcher(ctx, xmlrpc, xmlrpc_host, xmlrpc_port, poolsize, proxy, user_agent,
timeout, phantomjs_endpoint, puppeteer_endpoint, splash_endpoint, fetcher_cls,
async_mode=True, get_object=False, no_input=False):
"""
Run Fetcher.
"""
g = ctx.obj
Fetcher = load_cls(None, None, f... | python | def fetcher(ctx, xmlrpc, xmlrpc_host, xmlrpc_port, poolsize, proxy, user_agent,
timeout, phantomjs_endpoint, puppeteer_endpoint, splash_endpoint, fetcher_cls,
async_mode=True, get_object=False, no_input=False):
"""
Run Fetcher.
"""
g = ctx.obj
Fetcher = load_cls(None, None, f... | [
"def",
"fetcher",
"(",
"ctx",
",",
"xmlrpc",
",",
"xmlrpc_host",
",",
"xmlrpc_port",
",",
"poolsize",
",",
"proxy",
",",
"user_agent",
",",
"timeout",
",",
"phantomjs_endpoint",
",",
"puppeteer_endpoint",
",",
"splash_endpoint",
",",
"fetcher_cls",
",",
"async_m... | Run Fetcher. | [
"Run",
"Fetcher",
"."
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/run.py#L237-L269 |
29,834 | binux/pyspider | pyspider/run.py | processor | def processor(ctx, processor_cls, process_time_limit, enable_stdout_capture=True, get_object=False):
"""
Run Processor.
"""
g = ctx.obj
Processor = load_cls(None, None, processor_cls)
processor = Processor(projectdb=g.projectdb,
inqueue=g.fetcher2processor, status_queu... | python | def processor(ctx, processor_cls, process_time_limit, enable_stdout_capture=True, get_object=False):
"""
Run Processor.
"""
g = ctx.obj
Processor = load_cls(None, None, processor_cls)
processor = Processor(projectdb=g.projectdb,
inqueue=g.fetcher2processor, status_queu... | [
"def",
"processor",
"(",
"ctx",
",",
"processor_cls",
",",
"process_time_limit",
",",
"enable_stdout_capture",
"=",
"True",
",",
"get_object",
"=",
"False",
")",
":",
"g",
"=",
"ctx",
".",
"obj",
"Processor",
"=",
"load_cls",
"(",
"None",
",",
"None",
",",... | Run Processor. | [
"Run",
"Processor",
"."
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/run.py#L277-L294 |
29,835 | binux/pyspider | pyspider/run.py | result_worker | def result_worker(ctx, result_cls, get_object=False):
"""
Run result worker.
"""
g = ctx.obj
ResultWorker = load_cls(None, None, result_cls)
result_worker = ResultWorker(resultdb=g.resultdb, inqueue=g.processor2result)
g.instances.append(result_worker)
if g.get('testing_mode') or get_o... | python | def result_worker(ctx, result_cls, get_object=False):
"""
Run result worker.
"""
g = ctx.obj
ResultWorker = load_cls(None, None, result_cls)
result_worker = ResultWorker(resultdb=g.resultdb, inqueue=g.processor2result)
g.instances.append(result_worker)
if g.get('testing_mode') or get_o... | [
"def",
"result_worker",
"(",
"ctx",
",",
"result_cls",
",",
"get_object",
"=",
"False",
")",
":",
"g",
"=",
"ctx",
".",
"obj",
"ResultWorker",
"=",
"load_cls",
"(",
"None",
",",
"None",
",",
"result_cls",
")",
"result_worker",
"=",
"ResultWorker",
"(",
"... | Run result worker. | [
"Run",
"result",
"worker",
"."
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/run.py#L301-L314 |
29,836 | binux/pyspider | pyspider/run.py | phantomjs | def phantomjs(ctx, phantomjs_path, port, auto_restart, args):
"""
Run phantomjs fetcher if phantomjs is installed.
"""
args = args or ctx.default_map and ctx.default_map.get('args', [])
import subprocess
g = ctx.obj
_quit = []
phantomjs_fetcher = os.path.join(
os.path.dirname(py... | python | def phantomjs(ctx, phantomjs_path, port, auto_restart, args):
"""
Run phantomjs fetcher if phantomjs is installed.
"""
args = args or ctx.default_map and ctx.default_map.get('args', [])
import subprocess
g = ctx.obj
_quit = []
phantomjs_fetcher = os.path.join(
os.path.dirname(py... | [
"def",
"phantomjs",
"(",
"ctx",
",",
"phantomjs_path",
",",
"port",
",",
"auto_restart",
",",
"args",
")",
":",
"args",
"=",
"args",
"or",
"ctx",
".",
"default_map",
"and",
"ctx",
".",
"default_map",
".",
"get",
"(",
"'args'",
",",
"[",
"]",
")",
"im... | Run phantomjs fetcher if phantomjs is installed. | [
"Run",
"phantomjs",
"fetcher",
"if",
"phantomjs",
"is",
"installed",
"."
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/run.py#L402-L443 |
29,837 | binux/pyspider | pyspider/run.py | puppeteer | def puppeteer(ctx, port, auto_restart, args):
"""
Run puppeteer fetcher if puppeteer is installed.
"""
import subprocess
g = ctx.obj
_quit = []
puppeteer_fetcher = os.path.join(
os.path.dirname(pyspider.__file__), 'fetcher/puppeteer_fetcher.js')
cmd = ['node', puppeteer_fetcher,... | python | def puppeteer(ctx, port, auto_restart, args):
"""
Run puppeteer fetcher if puppeteer is installed.
"""
import subprocess
g = ctx.obj
_quit = []
puppeteer_fetcher = os.path.join(
os.path.dirname(pyspider.__file__), 'fetcher/puppeteer_fetcher.js')
cmd = ['node', puppeteer_fetcher,... | [
"def",
"puppeteer",
"(",
"ctx",
",",
"port",
",",
"auto_restart",
",",
"args",
")",
":",
"import",
"subprocess",
"g",
"=",
"ctx",
".",
"obj",
"_quit",
"=",
"[",
"]",
"puppeteer_fetcher",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
... | Run puppeteer fetcher if puppeteer is installed. | [
"Run",
"puppeteer",
"fetcher",
"if",
"puppeteer",
"is",
"installed",
"."
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/run.py#L450-L486 |
29,838 | binux/pyspider | pyspider/run.py | all | def all(ctx, fetcher_num, processor_num, result_worker_num, run_in):
"""
Run all the components in subprocess or thread
"""
ctx.obj['debug'] = False
g = ctx.obj
# FIXME: py34 cannot run components with threads
if run_in == 'subprocess' and os.name != 'nt':
run_in = utils.run_in_sub... | python | def all(ctx, fetcher_num, processor_num, result_worker_num, run_in):
"""
Run all the components in subprocess or thread
"""
ctx.obj['debug'] = False
g = ctx.obj
# FIXME: py34 cannot run components with threads
if run_in == 'subprocess' and os.name != 'nt':
run_in = utils.run_in_sub... | [
"def",
"all",
"(",
"ctx",
",",
"fetcher_num",
",",
"processor_num",
",",
"result_worker_num",
",",
"run_in",
")",
":",
"ctx",
".",
"obj",
"[",
"'debug'",
"]",
"=",
"False",
"g",
"=",
"ctx",
".",
"obj",
"# FIXME: py34 cannot run components with threads",
"if",
... | Run all the components in subprocess or thread | [
"Run",
"all",
"the",
"components",
"in",
"subprocess",
"or",
"thread"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/run.py#L498-L570 |
29,839 | binux/pyspider | pyspider/run.py | one | def one(ctx, interactive, enable_phantomjs, enable_puppeteer, scripts):
"""
One mode not only means all-in-one, it runs every thing in one process over
tornado.ioloop, for debug purpose
"""
ctx.obj['debug'] = False
g = ctx.obj
g['testing_mode'] = True
if scripts:
from pyspider.... | python | def one(ctx, interactive, enable_phantomjs, enable_puppeteer, scripts):
"""
One mode not only means all-in-one, it runs every thing in one process over
tornado.ioloop, for debug purpose
"""
ctx.obj['debug'] = False
g = ctx.obj
g['testing_mode'] = True
if scripts:
from pyspider.... | [
"def",
"one",
"(",
"ctx",
",",
"interactive",
",",
"enable_phantomjs",
",",
"enable_puppeteer",
",",
"scripts",
")",
":",
"ctx",
".",
"obj",
"[",
"'debug'",
"]",
"=",
"False",
"g",
"=",
"ctx",
".",
"obj",
"g",
"[",
"'testing_mode'",
"]",
"=",
"True",
... | One mode not only means all-in-one, it runs every thing in one process over
tornado.ioloop, for debug purpose | [
"One",
"mode",
"not",
"only",
"means",
"all",
"-",
"in",
"-",
"one",
"it",
"runs",
"every",
"thing",
"in",
"one",
"process",
"over",
"tornado",
".",
"ioloop",
"for",
"debug",
"purpose"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/run.py#L723-L793 |
29,840 | binux/pyspider | pyspider/run.py | send_message | def send_message(ctx, scheduler_rpc, project, message):
"""
Send Message to project from command line
"""
if isinstance(scheduler_rpc, six.string_types):
scheduler_rpc = connect_rpc(ctx, None, scheduler_rpc)
if scheduler_rpc is None and os.environ.get('SCHEDULER_NAME'):
scheduler_rpc... | python | def send_message(ctx, scheduler_rpc, project, message):
"""
Send Message to project from command line
"""
if isinstance(scheduler_rpc, six.string_types):
scheduler_rpc = connect_rpc(ctx, None, scheduler_rpc)
if scheduler_rpc is None and os.environ.get('SCHEDULER_NAME'):
scheduler_rpc... | [
"def",
"send_message",
"(",
"ctx",
",",
"scheduler_rpc",
",",
"project",
",",
"message",
")",
":",
"if",
"isinstance",
"(",
"scheduler_rpc",
",",
"six",
".",
"string_types",
")",
":",
"scheduler_rpc",
"=",
"connect_rpc",
"(",
"ctx",
",",
"None",
",",
"sche... | Send Message to project from command line | [
"Send",
"Message",
"to",
"project",
"from",
"command",
"line"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/run.py#L801-L823 |
29,841 | binux/pyspider | pyspider/libs/pprint.py | pformat | def pformat(object, indent=1, width=80, depth=None):
"""Format a Python object into a pretty-printed representation."""
return PrettyPrinter(indent=indent, width=width, depth=depth).pformat(object) | python | def pformat(object, indent=1, width=80, depth=None):
"""Format a Python object into a pretty-printed representation."""
return PrettyPrinter(indent=indent, width=width, depth=depth).pformat(object) | [
"def",
"pformat",
"(",
"object",
",",
"indent",
"=",
"1",
",",
"width",
"=",
"80",
",",
"depth",
"=",
"None",
")",
":",
"return",
"PrettyPrinter",
"(",
"indent",
"=",
"indent",
",",
"width",
"=",
"width",
",",
"depth",
"=",
"depth",
")",
".",
"pfor... | Format a Python object into a pretty-printed representation. | [
"Format",
"a",
"Python",
"object",
"into",
"a",
"pretty",
"-",
"printed",
"representation",
"."
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/libs/pprint.py#L61-L63 |
29,842 | binux/pyspider | pyspider/libs/pprint.py | PrettyPrinter.format | def format(self, object, context, maxlevels, level):
"""Format object for a specific context, returning a string
and flags indicating whether the representation is 'readable'
and whether the object represents a recursive construct.
"""
return _safe_repr(object, context, maxlevels... | python | def format(self, object, context, maxlevels, level):
"""Format object for a specific context, returning a string
and flags indicating whether the representation is 'readable'
and whether the object represents a recursive construct.
"""
return _safe_repr(object, context, maxlevels... | [
"def",
"format",
"(",
"self",
",",
"object",
",",
"context",
",",
"maxlevels",
",",
"level",
")",
":",
"return",
"_safe_repr",
"(",
"object",
",",
"context",
",",
"maxlevels",
",",
"level",
")"
] | Format object for a specific context, returning a string
and flags indicating whether the representation is 'readable'
and whether the object represents a recursive construct. | [
"Format",
"object",
"for",
"a",
"specific",
"context",
"returning",
"a",
"string",
"and",
"flags",
"indicating",
"whether",
"the",
"representation",
"is",
"readable",
"and",
"whether",
"the",
"object",
"represents",
"a",
"recursive",
"construct",
"."
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/libs/pprint.py#L243-L248 |
29,843 | binux/pyspider | pyspider/scheduler/token_bucket.py | Bucket.get | def get(self):
'''Get the number of tokens in bucket'''
now = time.time()
if self.bucket >= self.burst:
self.last_update = now
return self.bucket
bucket = self.rate * (now - self.last_update)
self.mutex.acquire()
if bucket > 1:
self.buc... | python | def get(self):
'''Get the number of tokens in bucket'''
now = time.time()
if self.bucket >= self.burst:
self.last_update = now
return self.bucket
bucket = self.rate * (now - self.last_update)
self.mutex.acquire()
if bucket > 1:
self.buc... | [
"def",
"get",
"(",
"self",
")",
":",
"now",
"=",
"time",
".",
"time",
"(",
")",
"if",
"self",
".",
"bucket",
">=",
"self",
".",
"burst",
":",
"self",
".",
"last_update",
"=",
"now",
"return",
"self",
".",
"bucket",
"bucket",
"=",
"self",
".",
"ra... | Get the number of tokens in bucket | [
"Get",
"the",
"number",
"of",
"tokens",
"in",
"bucket"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/token_bucket.py#L33-L47 |
29,844 | binux/pyspider | tools/migrate.py | migrate | def migrate(pool, from_connection, to_connection):
"""
Migrate tool for pyspider
"""
f = connect_database(from_connection)
t = connect_database(to_connection)
if isinstance(f, ProjectDB):
for each in f.get_all():
each = unicode_obj(each)
logging.info("projectdb: ... | python | def migrate(pool, from_connection, to_connection):
"""
Migrate tool for pyspider
"""
f = connect_database(from_connection)
t = connect_database(to_connection)
if isinstance(f, ProjectDB):
for each in f.get_all():
each = unicode_obj(each)
logging.info("projectdb: ... | [
"def",
"migrate",
"(",
"pool",
",",
"from_connection",
",",
"to_connection",
")",
":",
"f",
"=",
"connect_database",
"(",
"from_connection",
")",
"t",
"=",
"connect_database",
"(",
"to_connection",
")",
"if",
"isinstance",
"(",
"f",
",",
"ProjectDB",
")",
":... | Migrate tool for pyspider | [
"Migrate",
"tool",
"for",
"pyspider"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/tools/migrate.py#L43-L65 |
29,845 | binux/pyspider | pyspider/libs/dataurl.py | encode | def encode(data, mime_type='', charset='utf-8', base64=True):
"""
Encode data to DataURL
"""
if isinstance(data, six.text_type):
data = data.encode(charset)
else:
charset = None
if base64:
data = utils.text(b64encode(data))
else:
data = utils.text(quote(data))... | python | def encode(data, mime_type='', charset='utf-8', base64=True):
"""
Encode data to DataURL
"""
if isinstance(data, six.text_type):
data = data.encode(charset)
else:
charset = None
if base64:
data = utils.text(b64encode(data))
else:
data = utils.text(quote(data))... | [
"def",
"encode",
"(",
"data",
",",
"mime_type",
"=",
"''",
",",
"charset",
"=",
"'utf-8'",
",",
"base64",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"data",
",",
"six",
".",
"text_type",
")",
":",
"data",
"=",
"data",
".",
"encode",
"(",
"char... | Encode data to DataURL | [
"Encode",
"data",
"to",
"DataURL"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/libs/dataurl.py#L14-L38 |
29,846 | binux/pyspider | pyspider/libs/dataurl.py | decode | def decode(data_url):
"""
Decode DataURL data
"""
metadata, data = data_url.rsplit(',', 1)
_, metadata = metadata.split('data:', 1)
parts = metadata.split(';')
if parts[-1] == 'base64':
data = b64decode(data)
else:
data = unquote(data)
for part in parts:
if p... | python | def decode(data_url):
"""
Decode DataURL data
"""
metadata, data = data_url.rsplit(',', 1)
_, metadata = metadata.split('data:', 1)
parts = metadata.split(';')
if parts[-1] == 'base64':
data = b64decode(data)
else:
data = unquote(data)
for part in parts:
if p... | [
"def",
"decode",
"(",
"data_url",
")",
":",
"metadata",
",",
"data",
"=",
"data_url",
".",
"rsplit",
"(",
"','",
",",
"1",
")",
"_",
",",
"metadata",
"=",
"metadata",
".",
"split",
"(",
"'data:'",
",",
"1",
")",
"parts",
"=",
"metadata",
".",
"spli... | Decode DataURL data | [
"Decode",
"DataURL",
"data"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/libs/dataurl.py#L41-L56 |
29,847 | binux/pyspider | pyspider/libs/url.py | quote_chinese | def quote_chinese(url, encodeing="utf-8"):
"""Quote non-ascii characters"""
if isinstance(url, six.text_type):
return quote_chinese(url.encode(encodeing))
if six.PY3:
res = [six.int2byte(b).decode('latin-1') if b < 128 else '%%%02X' % b for b in url]
else:
res = [b if ord(b) < 12... | python | def quote_chinese(url, encodeing="utf-8"):
"""Quote non-ascii characters"""
if isinstance(url, six.text_type):
return quote_chinese(url.encode(encodeing))
if six.PY3:
res = [six.int2byte(b).decode('latin-1') if b < 128 else '%%%02X' % b for b in url]
else:
res = [b if ord(b) < 12... | [
"def",
"quote_chinese",
"(",
"url",
",",
"encodeing",
"=",
"\"utf-8\"",
")",
":",
"if",
"isinstance",
"(",
"url",
",",
"six",
".",
"text_type",
")",
":",
"return",
"quote_chinese",
"(",
"url",
".",
"encode",
"(",
"encodeing",
")",
")",
"if",
"six",
"."... | Quote non-ascii characters | [
"Quote",
"non",
"-",
"ascii",
"characters"
] | 3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9 | https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/libs/url.py#L62-L70 |
29,848 | lanpa/tensorboardX | examples/demo_caffe2.py | DownloadResource | def DownloadResource(url, path):
'''Downloads resources from s3 by url and unzips them to the provided path'''
import requests
from six import BytesIO
import zipfile
print("Downloading... {} to {}".format(url, path))
r = requests.get(url, stream=True)
z = zipfile.ZipFile(BytesIO(r.content))
... | python | def DownloadResource(url, path):
'''Downloads resources from s3 by url and unzips them to the provided path'''
import requests
from six import BytesIO
import zipfile
print("Downloading... {} to {}".format(url, path))
r = requests.get(url, stream=True)
z = zipfile.ZipFile(BytesIO(r.content))
... | [
"def",
"DownloadResource",
"(",
"url",
",",
"path",
")",
":",
"import",
"requests",
"from",
"six",
"import",
"BytesIO",
"import",
"zipfile",
"print",
"(",
"\"Downloading... {} to {}\"",
".",
"format",
"(",
"url",
",",
"path",
")",
")",
"r",
"=",
"requests",
... | Downloads resources from s3 by url and unzips them to the provided path | [
"Downloads",
"resources",
"from",
"s3",
"by",
"url",
"and",
"unzips",
"them",
"to",
"the",
"provided",
"path"
] | 0bf6c07d97b0745654fd9fab8ee3261ec707f253 | https://github.com/lanpa/tensorboardX/blob/0bf6c07d97b0745654fd9fab8ee3261ec707f253/examples/demo_caffe2.py#L28-L37 |
29,849 | lanpa/tensorboardX | examples/demo_caffe2.py | AddAccuracy | def AddAccuracy(model, softmax, label):
"""Adds an accuracy op to the model"""
accuracy = brew.accuracy(model, [softmax, label], "accuracy")
return accuracy | python | def AddAccuracy(model, softmax, label):
"""Adds an accuracy op to the model"""
accuracy = brew.accuracy(model, [softmax, label], "accuracy")
return accuracy | [
"def",
"AddAccuracy",
"(",
"model",
",",
"softmax",
",",
"label",
")",
":",
"accuracy",
"=",
"brew",
".",
"accuracy",
"(",
"model",
",",
"[",
"softmax",
",",
"label",
"]",
",",
"\"accuracy\"",
")",
"return",
"accuracy"
] | Adds an accuracy op to the model | [
"Adds",
"an",
"accuracy",
"op",
"to",
"the",
"model"
] | 0bf6c07d97b0745654fd9fab8ee3261ec707f253 | https://github.com/lanpa/tensorboardX/blob/0bf6c07d97b0745654fd9fab8ee3261ec707f253/examples/demo_caffe2.py#L130-L133 |
29,850 | lanpa/tensorboardX | examples/demo_caffe2.py | AddTrainingOperators | def AddTrainingOperators(model, softmax, label):
"""Adds training operators to the model."""
xent = model.LabelCrossEntropy([softmax, label], 'xent')
# compute the expected loss
loss = model.AveragedLoss(xent, "loss")
# track the accuracy of the model
AddAccuracy(model, softmax, label)
# use... | python | def AddTrainingOperators(model, softmax, label):
"""Adds training operators to the model."""
xent = model.LabelCrossEntropy([softmax, label], 'xent')
# compute the expected loss
loss = model.AveragedLoss(xent, "loss")
# track the accuracy of the model
AddAccuracy(model, softmax, label)
# use... | [
"def",
"AddTrainingOperators",
"(",
"model",
",",
"softmax",
",",
"label",
")",
":",
"xent",
"=",
"model",
".",
"LabelCrossEntropy",
"(",
"[",
"softmax",
",",
"label",
"]",
",",
"'xent'",
")",
"# compute the expected loss",
"loss",
"=",
"model",
".",
"Averag... | Adds training operators to the model. | [
"Adds",
"training",
"operators",
"to",
"the",
"model",
"."
] | 0bf6c07d97b0745654fd9fab8ee3261ec707f253 | https://github.com/lanpa/tensorboardX/blob/0bf6c07d97b0745654fd9fab8ee3261ec707f253/examples/demo_caffe2.py#L136-L160 |
29,851 | lanpa/tensorboardX | examples/demo_caffe2.py | AddBookkeepingOperators | def AddBookkeepingOperators(model):
"""This adds a few bookkeeping operators that we can inspect later.
These operators do not affect the training procedure: they only collect
statistics and prints them to file or to logs.
"""
# Print basically prints out the content of the blob. to_file=1 routes t... | python | def AddBookkeepingOperators(model):
"""This adds a few bookkeeping operators that we can inspect later.
These operators do not affect the training procedure: they only collect
statistics and prints them to file or to logs.
"""
# Print basically prints out the content of the blob. to_file=1 routes t... | [
"def",
"AddBookkeepingOperators",
"(",
"model",
")",
":",
"# Print basically prints out the content of the blob. to_file=1 routes the",
"# printed output to a file. The file is going to be stored under",
"# root_folder/[blob name]",
"model",
".",
"Print",
"(",
"'accuracy'",
",",
"[... | This adds a few bookkeeping operators that we can inspect later.
These operators do not affect the training procedure: they only collect
statistics and prints them to file or to logs. | [
"This",
"adds",
"a",
"few",
"bookkeeping",
"operators",
"that",
"we",
"can",
"inspect",
"later",
"."
] | 0bf6c07d97b0745654fd9fab8ee3261ec707f253 | https://github.com/lanpa/tensorboardX/blob/0bf6c07d97b0745654fd9fab8ee3261ec707f253/examples/demo_caffe2.py#L163-L178 |
29,852 | lanpa/tensorboardX | examples/chainer/plain_logger/net.py | VAE.get_loss_func | def get_loss_func(self, C=1.0, k=1):
"""Get loss function of VAE.
The loss value is equal to ELBO (Evidence Lower Bound)
multiplied by -1.
Args:
C (int): Usually this is 1.0. Can be changed to control the
second term of ELBO bound, which works as regularizat... | python | def get_loss_func(self, C=1.0, k=1):
"""Get loss function of VAE.
The loss value is equal to ELBO (Evidence Lower Bound)
multiplied by -1.
Args:
C (int): Usually this is 1.0. Can be changed to control the
second term of ELBO bound, which works as regularizat... | [
"def",
"get_loss_func",
"(",
"self",
",",
"C",
"=",
"1.0",
",",
"k",
"=",
"1",
")",
":",
"def",
"lf",
"(",
"x",
")",
":",
"mu",
",",
"ln_var",
"=",
"self",
".",
"encode",
"(",
"x",
")",
"batchsize",
"=",
"len",
"(",
"mu",
".",
"data",
")",
... | Get loss function of VAE.
The loss value is equal to ELBO (Evidence Lower Bound)
multiplied by -1.
Args:
C (int): Usually this is 1.0. Can be changed to control the
second term of ELBO bound, which works as regularization.
k (int): Number of Monte Carlo ... | [
"Get",
"loss",
"function",
"of",
"VAE",
"."
] | 0bf6c07d97b0745654fd9fab8ee3261ec707f253 | https://github.com/lanpa/tensorboardX/blob/0bf6c07d97b0745654fd9fab8ee3261ec707f253/examples/chainer/plain_logger/net.py#L41-L65 |
29,853 | keras-rl/keras-rl | rl/core.py | Processor.process_step | def process_step(self, observation, reward, done, info):
"""Processes an entire step by applying the processor to the observation, reward, and info arguments.
# Arguments
observation (object): An observation as obtained by the environment.
reward (float): A reward as obtained by... | python | def process_step(self, observation, reward, done, info):
"""Processes an entire step by applying the processor to the observation, reward, and info arguments.
# Arguments
observation (object): An observation as obtained by the environment.
reward (float): A reward as obtained by... | [
"def",
"process_step",
"(",
"self",
",",
"observation",
",",
"reward",
",",
"done",
",",
"info",
")",
":",
"observation",
"=",
"self",
".",
"process_observation",
"(",
"observation",
")",
"reward",
"=",
"self",
".",
"process_reward",
"(",
"reward",
")",
"i... | Processes an entire step by applying the processor to the observation, reward, and info arguments.
# Arguments
observation (object): An observation as obtained by the environment.
reward (float): A reward as obtained by the environment.
done (boolean): `True` if the environm... | [
"Processes",
"an",
"entire",
"step",
"by",
"applying",
"the",
"processor",
"to",
"the",
"observation",
"reward",
"and",
"info",
"arguments",
"."
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/core.py#L511-L526 |
29,854 | keras-rl/keras-rl | rl/policy.py | LinearAnnealedPolicy.get_current_value | def get_current_value(self):
"""Return current annealing value
# Returns
Value to use in annealing
"""
if self.agent.training:
# Linear annealed: f(x) = ax + b.
a = -float(self.value_max - self.value_min) / float(self.nb_steps)
b = float(s... | python | def get_current_value(self):
"""Return current annealing value
# Returns
Value to use in annealing
"""
if self.agent.training:
# Linear annealed: f(x) = ax + b.
a = -float(self.value_max - self.value_min) / float(self.nb_steps)
b = float(s... | [
"def",
"get_current_value",
"(",
"self",
")",
":",
"if",
"self",
".",
"agent",
".",
"training",
":",
"# Linear annealed: f(x) = ax + b.",
"a",
"=",
"-",
"float",
"(",
"self",
".",
"value_max",
"-",
"self",
".",
"value_min",
")",
"/",
"float",
"(",
"self",
... | Return current annealing value
# Returns
Value to use in annealing | [
"Return",
"current",
"annealing",
"value"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/policy.py#L62-L75 |
29,855 | keras-rl/keras-rl | rl/policy.py | LinearAnnealedPolicy.select_action | def select_action(self, **kwargs):
"""Choose an action to perform
# Returns
Action to take (int)
"""
setattr(self.inner_policy, self.attr, self.get_current_value())
return self.inner_policy.select_action(**kwargs) | python | def select_action(self, **kwargs):
"""Choose an action to perform
# Returns
Action to take (int)
"""
setattr(self.inner_policy, self.attr, self.get_current_value())
return self.inner_policy.select_action(**kwargs) | [
"def",
"select_action",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"setattr",
"(",
"self",
".",
"inner_policy",
",",
"self",
".",
"attr",
",",
"self",
".",
"get_current_value",
"(",
")",
")",
"return",
"self",
".",
"inner_policy",
".",
"select_actio... | Choose an action to perform
# Returns
Action to take (int) | [
"Choose",
"an",
"action",
"to",
"perform"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/policy.py#L77-L84 |
29,856 | keras-rl/keras-rl | rl/policy.py | LinearAnnealedPolicy.get_config | def get_config(self):
"""Return configurations of LinearAnnealedPolicy
# Returns
Dict of config
"""
config = super(LinearAnnealedPolicy, self).get_config()
config['attr'] = self.attr
config['value_max'] = self.value_max
config['value_min'] = self.valu... | python | def get_config(self):
"""Return configurations of LinearAnnealedPolicy
# Returns
Dict of config
"""
config = super(LinearAnnealedPolicy, self).get_config()
config['attr'] = self.attr
config['value_max'] = self.value_max
config['value_min'] = self.valu... | [
"def",
"get_config",
"(",
"self",
")",
":",
"config",
"=",
"super",
"(",
"LinearAnnealedPolicy",
",",
"self",
")",
".",
"get_config",
"(",
")",
"config",
"[",
"'attr'",
"]",
"=",
"self",
".",
"attr",
"config",
"[",
"'value_max'",
"]",
"=",
"self",
".",... | Return configurations of LinearAnnealedPolicy
# Returns
Dict of config | [
"Return",
"configurations",
"of",
"LinearAnnealedPolicy"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/policy.py#L105-L118 |
29,857 | keras-rl/keras-rl | rl/policy.py | EpsGreedyQPolicy.get_config | def get_config(self):
"""Return configurations of EpsGreedyQPolicy
# Returns
Dict of config
"""
config = super(EpsGreedyQPolicy, self).get_config()
config['eps'] = self.eps
return config | python | def get_config(self):
"""Return configurations of EpsGreedyQPolicy
# Returns
Dict of config
"""
config = super(EpsGreedyQPolicy, self).get_config()
config['eps'] = self.eps
return config | [
"def",
"get_config",
"(",
"self",
")",
":",
"config",
"=",
"super",
"(",
"EpsGreedyQPolicy",
",",
"self",
")",
".",
"get_config",
"(",
")",
"config",
"[",
"'eps'",
"]",
"=",
"self",
".",
"eps",
"return",
"config"
] | Return configurations of EpsGreedyQPolicy
# Returns
Dict of config | [
"Return",
"configurations",
"of",
"EpsGreedyQPolicy"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/policy.py#L171-L179 |
29,858 | keras-rl/keras-rl | rl/policy.py | BoltzmannQPolicy.get_config | def get_config(self):
"""Return configurations of BoltzmannQPolicy
# Returns
Dict of config
"""
config = super(BoltzmannQPolicy, self).get_config()
config['tau'] = self.tau
config['clip'] = self.clip
return config | python | def get_config(self):
"""Return configurations of BoltzmannQPolicy
# Returns
Dict of config
"""
config = super(BoltzmannQPolicy, self).get_config()
config['tau'] = self.tau
config['clip'] = self.clip
return config | [
"def",
"get_config",
"(",
"self",
")",
":",
"config",
"=",
"super",
"(",
"BoltzmannQPolicy",
",",
"self",
")",
".",
"get_config",
"(",
")",
"config",
"[",
"'tau'",
"]",
"=",
"self",
".",
"tau",
"config",
"[",
"'clip'",
"]",
"=",
"self",
".",
"clip",
... | Return configurations of BoltzmannQPolicy
# Returns
Dict of config | [
"Return",
"configurations",
"of",
"BoltzmannQPolicy"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/policy.py#L230-L239 |
29,859 | keras-rl/keras-rl | rl/policy.py | MaxBoltzmannQPolicy.get_config | def get_config(self):
"""Return configurations of MaxBoltzmannQPolicy
# Returns
Dict of config
"""
config = super(MaxBoltzmannQPolicy, self).get_config()
config['eps'] = self.eps
config['tau'] = self.tau
config['clip'] = self.clip
return confi... | python | def get_config(self):
"""Return configurations of MaxBoltzmannQPolicy
# Returns
Dict of config
"""
config = super(MaxBoltzmannQPolicy, self).get_config()
config['eps'] = self.eps
config['tau'] = self.tau
config['clip'] = self.clip
return confi... | [
"def",
"get_config",
"(",
"self",
")",
":",
"config",
"=",
"super",
"(",
"MaxBoltzmannQPolicy",
",",
"self",
")",
".",
"get_config",
"(",
")",
"config",
"[",
"'eps'",
"]",
"=",
"self",
".",
"eps",
"config",
"[",
"'tau'",
"]",
"=",
"self",
".",
"tau",... | Return configurations of MaxBoltzmannQPolicy
# Returns
Dict of config | [
"Return",
"configurations",
"of",
"MaxBoltzmannQPolicy"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/policy.py#L280-L290 |
29,860 | keras-rl/keras-rl | rl/policy.py | BoltzmannGumbelQPolicy.get_config | def get_config(self):
"""Return configurations of BoltzmannGumbelQPolicy
# Returns
Dict of config
"""
config = super(BoltzmannGumbelQPolicy, self).get_config()
config['C'] = self.C
return config | python | def get_config(self):
"""Return configurations of BoltzmannGumbelQPolicy
# Returns
Dict of config
"""
config = super(BoltzmannGumbelQPolicy, self).get_config()
config['C'] = self.C
return config | [
"def",
"get_config",
"(",
"self",
")",
":",
"config",
"=",
"super",
"(",
"BoltzmannGumbelQPolicy",
",",
"self",
")",
".",
"get_config",
"(",
")",
"config",
"[",
"'C'",
"]",
"=",
"self",
".",
"C",
"return",
"config"
] | Return configurations of BoltzmannGumbelQPolicy
# Returns
Dict of config | [
"Return",
"configurations",
"of",
"BoltzmannGumbelQPolicy"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/policy.py#L348-L356 |
29,861 | keras-rl/keras-rl | rl/callbacks.py | CallbackList._set_env | def _set_env(self, env):
""" Set environment for each callback in callbackList """
for callback in self.callbacks:
if callable(getattr(callback, '_set_env', None)):
callback._set_env(env) | python | def _set_env(self, env):
""" Set environment for each callback in callbackList """
for callback in self.callbacks:
if callable(getattr(callback, '_set_env', None)):
callback._set_env(env) | [
"def",
"_set_env",
"(",
"self",
",",
"env",
")",
":",
"for",
"callback",
"in",
"self",
".",
"callbacks",
":",
"if",
"callable",
"(",
"getattr",
"(",
"callback",
",",
"'_set_env'",
",",
"None",
")",
")",
":",
"callback",
".",
"_set_env",
"(",
"env",
"... | Set environment for each callback in callbackList | [
"Set",
"environment",
"for",
"each",
"callback",
"in",
"callbackList"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L45-L49 |
29,862 | keras-rl/keras-rl | rl/callbacks.py | CallbackList.on_episode_begin | def on_episode_begin(self, episode, logs={}):
""" Called at beginning of each episode for each callback in callbackList"""
for callback in self.callbacks:
# Check if callback supports the more appropriate `on_episode_begin` callback.
# If not, fall back to `on_epoch_begin` to be ... | python | def on_episode_begin(self, episode, logs={}):
""" Called at beginning of each episode for each callback in callbackList"""
for callback in self.callbacks:
# Check if callback supports the more appropriate `on_episode_begin` callback.
# If not, fall back to `on_epoch_begin` to be ... | [
"def",
"on_episode_begin",
"(",
"self",
",",
"episode",
",",
"logs",
"=",
"{",
"}",
")",
":",
"for",
"callback",
"in",
"self",
".",
"callbacks",
":",
"# Check if callback supports the more appropriate `on_episode_begin` callback.",
"# If not, fall back to `on_epoch_begin` t... | Called at beginning of each episode for each callback in callbackList | [
"Called",
"at",
"beginning",
"of",
"each",
"episode",
"for",
"each",
"callback",
"in",
"callbackList"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L51-L59 |
29,863 | keras-rl/keras-rl | rl/callbacks.py | CallbackList.on_episode_end | def on_episode_end(self, episode, logs={}):
""" Called at end of each episode for each callback in callbackList"""
for callback in self.callbacks:
# Check if callback supports the more appropriate `on_episode_end` callback.
# If not, fall back to `on_epoch_end` to be compatible w... | python | def on_episode_end(self, episode, logs={}):
""" Called at end of each episode for each callback in callbackList"""
for callback in self.callbacks:
# Check if callback supports the more appropriate `on_episode_end` callback.
# If not, fall back to `on_epoch_end` to be compatible w... | [
"def",
"on_episode_end",
"(",
"self",
",",
"episode",
",",
"logs",
"=",
"{",
"}",
")",
":",
"for",
"callback",
"in",
"self",
".",
"callbacks",
":",
"# Check if callback supports the more appropriate `on_episode_end` callback.",
"# If not, fall back to `on_epoch_end` to be c... | Called at end of each episode for each callback in callbackList | [
"Called",
"at",
"end",
"of",
"each",
"episode",
"for",
"each",
"callback",
"in",
"callbackList"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L61-L69 |
29,864 | keras-rl/keras-rl | rl/callbacks.py | CallbackList.on_step_begin | def on_step_begin(self, step, logs={}):
""" Called at beginning of each step for each callback in callbackList"""
for callback in self.callbacks:
# Check if callback supports the more appropriate `on_step_begin` callback.
# If not, fall back to `on_batch_begin` to be compatible w... | python | def on_step_begin(self, step, logs={}):
""" Called at beginning of each step for each callback in callbackList"""
for callback in self.callbacks:
# Check if callback supports the more appropriate `on_step_begin` callback.
# If not, fall back to `on_batch_begin` to be compatible w... | [
"def",
"on_step_begin",
"(",
"self",
",",
"step",
",",
"logs",
"=",
"{",
"}",
")",
":",
"for",
"callback",
"in",
"self",
".",
"callbacks",
":",
"# Check if callback supports the more appropriate `on_step_begin` callback.",
"# If not, fall back to `on_batch_begin` to be comp... | Called at beginning of each step for each callback in callbackList | [
"Called",
"at",
"beginning",
"of",
"each",
"step",
"for",
"each",
"callback",
"in",
"callbackList"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L71-L79 |
29,865 | keras-rl/keras-rl | rl/callbacks.py | CallbackList.on_step_end | def on_step_end(self, step, logs={}):
""" Called at end of each step for each callback in callbackList"""
for callback in self.callbacks:
# Check if callback supports the more appropriate `on_step_end` callback.
# If not, fall back to `on_batch_end` to be compatible with built-in... | python | def on_step_end(self, step, logs={}):
""" Called at end of each step for each callback in callbackList"""
for callback in self.callbacks:
# Check if callback supports the more appropriate `on_step_end` callback.
# If not, fall back to `on_batch_end` to be compatible with built-in... | [
"def",
"on_step_end",
"(",
"self",
",",
"step",
",",
"logs",
"=",
"{",
"}",
")",
":",
"for",
"callback",
"in",
"self",
".",
"callbacks",
":",
"# Check if callback supports the more appropriate `on_step_end` callback.",
"# If not, fall back to `on_batch_end` to be compatible... | Called at end of each step for each callback in callbackList | [
"Called",
"at",
"end",
"of",
"each",
"step",
"for",
"each",
"callback",
"in",
"callbackList"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L81-L89 |
29,866 | keras-rl/keras-rl | rl/callbacks.py | CallbackList.on_action_begin | def on_action_begin(self, action, logs={}):
""" Called at beginning of each action for each callback in callbackList"""
for callback in self.callbacks:
if callable(getattr(callback, 'on_action_begin', None)):
callback.on_action_begin(action, logs=logs) | python | def on_action_begin(self, action, logs={}):
""" Called at beginning of each action for each callback in callbackList"""
for callback in self.callbacks:
if callable(getattr(callback, 'on_action_begin', None)):
callback.on_action_begin(action, logs=logs) | [
"def",
"on_action_begin",
"(",
"self",
",",
"action",
",",
"logs",
"=",
"{",
"}",
")",
":",
"for",
"callback",
"in",
"self",
".",
"callbacks",
":",
"if",
"callable",
"(",
"getattr",
"(",
"callback",
",",
"'on_action_begin'",
",",
"None",
")",
")",
":",... | Called at beginning of each action for each callback in callbackList | [
"Called",
"at",
"beginning",
"of",
"each",
"action",
"for",
"each",
"callback",
"in",
"callbackList"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L91-L95 |
29,867 | keras-rl/keras-rl | rl/callbacks.py | CallbackList.on_action_end | def on_action_end(self, action, logs={}):
""" Called at end of each action for each callback in callbackList"""
for callback in self.callbacks:
if callable(getattr(callback, 'on_action_end', None)):
callback.on_action_end(action, logs=logs) | python | def on_action_end(self, action, logs={}):
""" Called at end of each action for each callback in callbackList"""
for callback in self.callbacks:
if callable(getattr(callback, 'on_action_end', None)):
callback.on_action_end(action, logs=logs) | [
"def",
"on_action_end",
"(",
"self",
",",
"action",
",",
"logs",
"=",
"{",
"}",
")",
":",
"for",
"callback",
"in",
"self",
".",
"callbacks",
":",
"if",
"callable",
"(",
"getattr",
"(",
"callback",
",",
"'on_action_end'",
",",
"None",
")",
")",
":",
"... | Called at end of each action for each callback in callbackList | [
"Called",
"at",
"end",
"of",
"each",
"action",
"for",
"each",
"callback",
"in",
"callbackList"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L97-L101 |
29,868 | keras-rl/keras-rl | rl/callbacks.py | TrainEpisodeLogger.on_train_begin | def on_train_begin(self, logs):
""" Print training values at beginning of training """
self.train_start = timeit.default_timer()
self.metrics_names = self.model.metrics_names
print('Training for {} steps ...'.format(self.params['nb_steps'])) | python | def on_train_begin(self, logs):
""" Print training values at beginning of training """
self.train_start = timeit.default_timer()
self.metrics_names = self.model.metrics_names
print('Training for {} steps ...'.format(self.params['nb_steps'])) | [
"def",
"on_train_begin",
"(",
"self",
",",
"logs",
")",
":",
"self",
".",
"train_start",
"=",
"timeit",
".",
"default_timer",
"(",
")",
"self",
".",
"metrics_names",
"=",
"self",
".",
"model",
".",
"metrics_names",
"print",
"(",
"'Training for {} steps ...'",
... | Print training values at beginning of training | [
"Print",
"training",
"values",
"at",
"beginning",
"of",
"training"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L133-L137 |
29,869 | keras-rl/keras-rl | rl/callbacks.py | TrainEpisodeLogger.on_train_end | def on_train_end(self, logs):
""" Print training time at end of training """
duration = timeit.default_timer() - self.train_start
print('done, took {:.3f} seconds'.format(duration)) | python | def on_train_end(self, logs):
""" Print training time at end of training """
duration = timeit.default_timer() - self.train_start
print('done, took {:.3f} seconds'.format(duration)) | [
"def",
"on_train_end",
"(",
"self",
",",
"logs",
")",
":",
"duration",
"=",
"timeit",
".",
"default_timer",
"(",
")",
"-",
"self",
".",
"train_start",
"print",
"(",
"'done, took {:.3f} seconds'",
".",
"format",
"(",
"duration",
")",
")"
] | Print training time at end of training | [
"Print",
"training",
"time",
"at",
"end",
"of",
"training"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L139-L142 |
29,870 | keras-rl/keras-rl | rl/callbacks.py | TrainEpisodeLogger.on_episode_begin | def on_episode_begin(self, episode, logs):
""" Reset environment variables at beginning of each episode """
self.episode_start[episode] = timeit.default_timer()
self.observations[episode] = []
self.rewards[episode] = []
self.actions[episode] = []
self.metrics[episode] = [... | python | def on_episode_begin(self, episode, logs):
""" Reset environment variables at beginning of each episode """
self.episode_start[episode] = timeit.default_timer()
self.observations[episode] = []
self.rewards[episode] = []
self.actions[episode] = []
self.metrics[episode] = [... | [
"def",
"on_episode_begin",
"(",
"self",
",",
"episode",
",",
"logs",
")",
":",
"self",
".",
"episode_start",
"[",
"episode",
"]",
"=",
"timeit",
".",
"default_timer",
"(",
")",
"self",
".",
"observations",
"[",
"episode",
"]",
"=",
"[",
"]",
"self",
".... | Reset environment variables at beginning of each episode | [
"Reset",
"environment",
"variables",
"at",
"beginning",
"of",
"each",
"episode"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L144-L150 |
29,871 | keras-rl/keras-rl | rl/callbacks.py | TrainEpisodeLogger.on_episode_end | def on_episode_end(self, episode, logs):
""" Compute and print training statistics of the episode when done """
duration = timeit.default_timer() - self.episode_start[episode]
episode_steps = len(self.observations[episode])
# Format all metrics.
metrics = np.array(self.metrics[e... | python | def on_episode_end(self, episode, logs):
""" Compute and print training statistics of the episode when done """
duration = timeit.default_timer() - self.episode_start[episode]
episode_steps = len(self.observations[episode])
# Format all metrics.
metrics = np.array(self.metrics[e... | [
"def",
"on_episode_end",
"(",
"self",
",",
"episode",
",",
"logs",
")",
":",
"duration",
"=",
"timeit",
".",
"default_timer",
"(",
")",
"-",
"self",
".",
"episode_start",
"[",
"episode",
"]",
"episode_steps",
"=",
"len",
"(",
"self",
".",
"observations",
... | Compute and print training statistics of the episode when done | [
"Compute",
"and",
"print",
"training",
"statistics",
"of",
"the",
"episode",
"when",
"done"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L152-L203 |
29,872 | keras-rl/keras-rl | rl/callbacks.py | TrainEpisodeLogger.on_step_end | def on_step_end(self, step, logs):
""" Update statistics of episode after each step """
episode = logs['episode']
self.observations[episode].append(logs['observation'])
self.rewards[episode].append(logs['reward'])
self.actions[episode].append(logs['action'])
self.metrics[... | python | def on_step_end(self, step, logs):
""" Update statistics of episode after each step """
episode = logs['episode']
self.observations[episode].append(logs['observation'])
self.rewards[episode].append(logs['reward'])
self.actions[episode].append(logs['action'])
self.metrics[... | [
"def",
"on_step_end",
"(",
"self",
",",
"step",
",",
"logs",
")",
":",
"episode",
"=",
"logs",
"[",
"'episode'",
"]",
"self",
".",
"observations",
"[",
"episode",
"]",
".",
"append",
"(",
"logs",
"[",
"'observation'",
"]",
")",
"self",
".",
"rewards",
... | Update statistics of episode after each step | [
"Update",
"statistics",
"of",
"episode",
"after",
"each",
"step"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L205-L212 |
29,873 | keras-rl/keras-rl | rl/callbacks.py | TrainIntervalLogger.on_step_begin | def on_step_begin(self, step, logs):
""" Print metrics if interval is over """
if self.step % self.interval == 0:
if len(self.episode_rewards) > 0:
metrics = np.array(self.metrics)
assert metrics.shape == (self.interval, len(self.metrics_names))
... | python | def on_step_begin(self, step, logs):
""" Print metrics if interval is over """
if self.step % self.interval == 0:
if len(self.episode_rewards) > 0:
metrics = np.array(self.metrics)
assert metrics.shape == (self.interval, len(self.metrics_names))
... | [
"def",
"on_step_begin",
"(",
"self",
",",
"step",
",",
"logs",
")",
":",
"if",
"self",
".",
"step",
"%",
"self",
".",
"interval",
"==",
"0",
":",
"if",
"len",
"(",
"self",
".",
"episode_rewards",
")",
">",
"0",
":",
"metrics",
"=",
"np",
".",
"ar... | Print metrics if interval is over | [
"Print",
"metrics",
"if",
"interval",
"is",
"over"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L241-L265 |
29,874 | keras-rl/keras-rl | rl/callbacks.py | TrainIntervalLogger.on_step_end | def on_step_end(self, step, logs):
""" Update progression bar at the end of each step """
if self.info_names is None:
self.info_names = logs['info'].keys()
values = [('reward', logs['reward'])]
if KERAS_VERSION > '2.1.3':
self.progbar.update((self.step % self.inte... | python | def on_step_end(self, step, logs):
""" Update progression bar at the end of each step """
if self.info_names is None:
self.info_names = logs['info'].keys()
values = [('reward', logs['reward'])]
if KERAS_VERSION > '2.1.3':
self.progbar.update((self.step % self.inte... | [
"def",
"on_step_end",
"(",
"self",
",",
"step",
",",
"logs",
")",
":",
"if",
"self",
".",
"info_names",
"is",
"None",
":",
"self",
".",
"info_names",
"=",
"logs",
"[",
"'info'",
"]",
".",
"keys",
"(",
")",
"values",
"=",
"[",
"(",
"'reward'",
",",
... | Update progression bar at the end of each step | [
"Update",
"progression",
"bar",
"at",
"the",
"end",
"of",
"each",
"step"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L267-L279 |
29,875 | keras-rl/keras-rl | rl/callbacks.py | FileLogger.on_episode_begin | def on_episode_begin(self, episode, logs):
""" Initialize metrics at the beginning of each episode """
assert episode not in self.metrics
assert episode not in self.starts
self.metrics[episode] = []
self.starts[episode] = timeit.default_timer() | python | def on_episode_begin(self, episode, logs):
""" Initialize metrics at the beginning of each episode """
assert episode not in self.metrics
assert episode not in self.starts
self.metrics[episode] = []
self.starts[episode] = timeit.default_timer() | [
"def",
"on_episode_begin",
"(",
"self",
",",
"episode",
",",
"logs",
")",
":",
"assert",
"episode",
"not",
"in",
"self",
".",
"metrics",
"assert",
"episode",
"not",
"in",
"self",
".",
"starts",
"self",
".",
"metrics",
"[",
"episode",
"]",
"=",
"[",
"]"... | Initialize metrics at the beginning of each episode | [
"Initialize",
"metrics",
"at",
"the",
"beginning",
"of",
"each",
"episode"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L305-L310 |
29,876 | keras-rl/keras-rl | rl/callbacks.py | FileLogger.on_episode_end | def on_episode_end(self, episode, logs):
""" Compute and print metrics at the end of each episode """
duration = timeit.default_timer() - self.starts[episode]
metrics = self.metrics[episode]
if np.isnan(metrics).all():
mean_metrics = np.array([np.nan for _ in self.metrics_n... | python | def on_episode_end(self, episode, logs):
""" Compute and print metrics at the end of each episode """
duration = timeit.default_timer() - self.starts[episode]
metrics = self.metrics[episode]
if np.isnan(metrics).all():
mean_metrics = np.array([np.nan for _ in self.metrics_n... | [
"def",
"on_episode_end",
"(",
"self",
",",
"episode",
",",
"logs",
")",
":",
"duration",
"=",
"timeit",
".",
"default_timer",
"(",
")",
"-",
"self",
".",
"starts",
"[",
"episode",
"]",
"metrics",
"=",
"self",
".",
"metrics",
"[",
"episode",
"]",
"if",
... | Compute and print metrics at the end of each episode | [
"Compute",
"and",
"print",
"metrics",
"at",
"the",
"end",
"of",
"each",
"episode"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L312-L336 |
29,877 | keras-rl/keras-rl | rl/callbacks.py | FileLogger.save_data | def save_data(self):
""" Save metrics in a json file """
if len(self.data.keys()) == 0:
return
# Sort everything by episode.
assert 'episode' in self.data
sorted_indexes = np.argsort(self.data['episode'])
sorted_data = {}
for key, values in self.data.... | python | def save_data(self):
""" Save metrics in a json file """
if len(self.data.keys()) == 0:
return
# Sort everything by episode.
assert 'episode' in self.data
sorted_indexes = np.argsort(self.data['episode'])
sorted_data = {}
for key, values in self.data.... | [
"def",
"save_data",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"data",
".",
"keys",
"(",
")",
")",
"==",
"0",
":",
"return",
"# Sort everything by episode.",
"assert",
"'episode'",
"in",
"self",
".",
"data",
"sorted_indexes",
"=",
"np",
".",
... | Save metrics in a json file | [
"Save",
"metrics",
"in",
"a",
"json",
"file"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L342-L360 |
29,878 | keras-rl/keras-rl | rl/callbacks.py | ModelIntervalCheckpoint.on_step_end | def on_step_end(self, step, logs={}):
""" Save weights at interval steps during training """
self.total_steps += 1
if self.total_steps % self.interval != 0:
# Nothing to do.
return
filepath = self.filepath.format(step=self.total_steps, **logs)
if self.ver... | python | def on_step_end(self, step, logs={}):
""" Save weights at interval steps during training """
self.total_steps += 1
if self.total_steps % self.interval != 0:
# Nothing to do.
return
filepath = self.filepath.format(step=self.total_steps, **logs)
if self.ver... | [
"def",
"on_step_end",
"(",
"self",
",",
"step",
",",
"logs",
"=",
"{",
"}",
")",
":",
"self",
".",
"total_steps",
"+=",
"1",
"if",
"self",
".",
"total_steps",
"%",
"self",
".",
"interval",
"!=",
"0",
":",
"# Nothing to do.",
"return",
"filepath",
"=",
... | Save weights at interval steps during training | [
"Save",
"weights",
"at",
"interval",
"steps",
"during",
"training"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/callbacks.py#L377-L387 |
29,879 | keras-rl/keras-rl | rl/memory.py | zeroed_observation | def zeroed_observation(observation):
"""Return an array of zeros with same shape as given observation
# Argument
observation (list): List of observation
# Return
A np.ndarray of zeros with observation.shape
"""
if hasattr(observation, 'shape'):
return np.zeros(observati... | python | def zeroed_observation(observation):
"""Return an array of zeros with same shape as given observation
# Argument
observation (list): List of observation
# Return
A np.ndarray of zeros with observation.shape
"""
if hasattr(observation, 'shape'):
return np.zeros(observati... | [
"def",
"zeroed_observation",
"(",
"observation",
")",
":",
"if",
"hasattr",
"(",
"observation",
",",
"'shape'",
")",
":",
"return",
"np",
".",
"zeros",
"(",
"observation",
".",
"shape",
")",
"elif",
"hasattr",
"(",
"observation",
",",
"'__iter__'",
")",
":... | Return an array of zeros with same shape as given observation
# Argument
observation (list): List of observation
# Return
A np.ndarray of zeros with observation.shape | [
"Return",
"an",
"array",
"of",
"zeros",
"with",
"same",
"shape",
"as",
"given",
"observation"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/memory.py#L85-L102 |
29,880 | keras-rl/keras-rl | rl/memory.py | Memory.get_recent_state | def get_recent_state(self, current_observation):
"""Return list of last observations
# Argument
current_observation (object): Last observation
# Returns
A list of the last observations
"""
# This code is slightly complicated by the fact that subsequent o... | python | def get_recent_state(self, current_observation):
"""Return list of last observations
# Argument
current_observation (object): Last observation
# Returns
A list of the last observations
"""
# This code is slightly complicated by the fact that subsequent o... | [
"def",
"get_recent_state",
"(",
"self",
",",
"current_observation",
")",
":",
"# This code is slightly complicated by the fact that subsequent observations might be",
"# from different episodes. We ensure that an experience never spans multiple episodes.",
"# This is probably not that important ... | Return list of last observations
# Argument
current_observation (object): Last observation
# Returns
A list of the last observations | [
"Return",
"list",
"of",
"last",
"observations"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/memory.py#L120-L144 |
29,881 | keras-rl/keras-rl | rl/memory.py | SequentialMemory.sample | def sample(self, batch_size, batch_idxs=None):
"""Return a randomized batch of experiences
# Argument
batch_size (int): Size of the all batch
batch_idxs (int): Indexes to extract
# Returns
A list of experiences randomly selected
"""
# It is no... | python | def sample(self, batch_size, batch_idxs=None):
"""Return a randomized batch of experiences
# Argument
batch_size (int): Size of the all batch
batch_idxs (int): Indexes to extract
# Returns
A list of experiences randomly selected
"""
# It is no... | [
"def",
"sample",
"(",
"self",
",",
"batch_size",
",",
"batch_idxs",
"=",
"None",
")",
":",
"# It is not possible to tell whether the first state in the memory is terminal, because it",
"# would require access to the \"terminal\" flag associated to the previous state. As a result",
"# we ... | Return a randomized batch of experiences
# Argument
batch_size (int): Size of the all batch
batch_idxs (int): Indexes to extract
# Returns
A list of experiences randomly selected | [
"Return",
"a",
"randomized",
"batch",
"of",
"experiences"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/memory.py#L171-L239 |
29,882 | keras-rl/keras-rl | rl/memory.py | SequentialMemory.append | def append(self, observation, action, reward, terminal, training=True):
"""Append an observation to the memory
# Argument
observation (dict): Observation returned by environment
action (int): Action taken to obtain this observation
reward (float): Reward obtained by ... | python | def append(self, observation, action, reward, terminal, training=True):
"""Append an observation to the memory
# Argument
observation (dict): Observation returned by environment
action (int): Action taken to obtain this observation
reward (float): Reward obtained by ... | [
"def",
"append",
"(",
"self",
",",
"observation",
",",
"action",
",",
"reward",
",",
"terminal",
",",
"training",
"=",
"True",
")",
":",
"super",
"(",
"SequentialMemory",
",",
"self",
")",
".",
"append",
"(",
"observation",
",",
"action",
",",
"reward",
... | Append an observation to the memory
# Argument
observation (dict): Observation returned by environment
action (int): Action taken to obtain this observation
reward (float): Reward obtained by taking this action
terminal (boolean): Is the state terminal | [
"Append",
"an",
"observation",
"to",
"the",
"memory"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/memory.py#L241-L258 |
29,883 | keras-rl/keras-rl | rl/memory.py | SequentialMemory.get_config | def get_config(self):
"""Return configurations of SequentialMemory
# Returns
Dict of config
"""
config = super(SequentialMemory, self).get_config()
config['limit'] = self.limit
return config | python | def get_config(self):
"""Return configurations of SequentialMemory
# Returns
Dict of config
"""
config = super(SequentialMemory, self).get_config()
config['limit'] = self.limit
return config | [
"def",
"get_config",
"(",
"self",
")",
":",
"config",
"=",
"super",
"(",
"SequentialMemory",
",",
"self",
")",
".",
"get_config",
"(",
")",
"config",
"[",
"'limit'",
"]",
"=",
"self",
".",
"limit",
"return",
"config"
] | Return configurations of SequentialMemory
# Returns
Dict of config | [
"Return",
"configurations",
"of",
"SequentialMemory"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/memory.py#L269-L277 |
29,884 | keras-rl/keras-rl | rl/memory.py | EpisodeParameterMemory.sample | def sample(self, batch_size, batch_idxs=None):
"""Return a randomized batch of params and rewards
# Argument
batch_size (int): Size of the all batch
batch_idxs (int): Indexes to extract
# Returns
A list of params randomly selected and a list of associated rew... | python | def sample(self, batch_size, batch_idxs=None):
"""Return a randomized batch of params and rewards
# Argument
batch_size (int): Size of the all batch
batch_idxs (int): Indexes to extract
# Returns
A list of params randomly selected and a list of associated rew... | [
"def",
"sample",
"(",
"self",
",",
"batch_size",
",",
"batch_idxs",
"=",
"None",
")",
":",
"if",
"batch_idxs",
"is",
"None",
":",
"batch_idxs",
"=",
"sample_batch_indexes",
"(",
"0",
",",
"self",
".",
"nb_entries",
",",
"size",
"=",
"batch_size",
")",
"a... | Return a randomized batch of params and rewards
# Argument
batch_size (int): Size of the all batch
batch_idxs (int): Indexes to extract
# Returns
A list of params randomly selected and a list of associated rewards | [
"Return",
"a",
"randomized",
"batch",
"of",
"params",
"and",
"rewards"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/memory.py#L289-L307 |
29,885 | keras-rl/keras-rl | rl/memory.py | EpisodeParameterMemory.append | def append(self, observation, action, reward, terminal, training=True):
"""Append a reward to the memory
# Argument
observation (dict): Observation returned by environment
action (int): Action taken to obtain this observation
reward (float): Reward obtained by taking... | python | def append(self, observation, action, reward, terminal, training=True):
"""Append a reward to the memory
# Argument
observation (dict): Observation returned by environment
action (int): Action taken to obtain this observation
reward (float): Reward obtained by taking... | [
"def",
"append",
"(",
"self",
",",
"observation",
",",
"action",
",",
"reward",
",",
"terminal",
",",
"training",
"=",
"True",
")",
":",
"super",
"(",
"EpisodeParameterMemory",
",",
"self",
")",
".",
"append",
"(",
"observation",
",",
"action",
",",
"rew... | Append a reward to the memory
# Argument
observation (dict): Observation returned by environment
action (int): Action taken to obtain this observation
reward (float): Reward obtained by taking this action
terminal (boolean): Is the state terminal | [
"Append",
"a",
"reward",
"to",
"the",
"memory"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/memory.py#L309-L320 |
29,886 | keras-rl/keras-rl | rl/memory.py | EpisodeParameterMemory.finalize_episode | def finalize_episode(self, params):
"""Closes the current episode, sums up rewards and stores the parameters
# Argument
params (object): Parameters associated with the episode to be stored and then retrieved back in sample()
"""
total_reward = sum(self.intermediate_rewards)
... | python | def finalize_episode(self, params):
"""Closes the current episode, sums up rewards and stores the parameters
# Argument
params (object): Parameters associated with the episode to be stored and then retrieved back in sample()
"""
total_reward = sum(self.intermediate_rewards)
... | [
"def",
"finalize_episode",
"(",
"self",
",",
"params",
")",
":",
"total_reward",
"=",
"sum",
"(",
"self",
".",
"intermediate_rewards",
")",
"self",
".",
"total_rewards",
".",
"append",
"(",
"total_reward",
")",
"self",
".",
"params",
".",
"append",
"(",
"p... | Closes the current episode, sums up rewards and stores the parameters
# Argument
params (object): Parameters associated with the episode to be stored and then retrieved back in sample() | [
"Closes",
"the",
"current",
"episode",
"sums",
"up",
"rewards",
"and",
"stores",
"the",
"parameters"
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/memory.py#L322-L331 |
29,887 | keras-rl/keras-rl | rl/common/cmd_util.py | make_gym_env | def make_gym_env(env_id, num_env=2, seed=123, wrapper_kwargs=None, start_index=0):
"""
Create a wrapped, SubprocVecEnv for Gym Environments.
"""
if wrapper_kwargs is None:
wrapper_kwargs = {}
def make_env(rank): # pylint: disable=C0111
def _thunk():
env = gym.make(env_id... | python | def make_gym_env(env_id, num_env=2, seed=123, wrapper_kwargs=None, start_index=0):
"""
Create a wrapped, SubprocVecEnv for Gym Environments.
"""
if wrapper_kwargs is None:
wrapper_kwargs = {}
def make_env(rank): # pylint: disable=C0111
def _thunk():
env = gym.make(env_id... | [
"def",
"make_gym_env",
"(",
"env_id",
",",
"num_env",
"=",
"2",
",",
"seed",
"=",
"123",
",",
"wrapper_kwargs",
"=",
"None",
",",
"start_index",
"=",
"0",
")",
":",
"if",
"wrapper_kwargs",
"is",
"None",
":",
"wrapper_kwargs",
"=",
"{",
"}",
"def",
"mak... | Create a wrapped, SubprocVecEnv for Gym Environments. | [
"Create",
"a",
"wrapped",
"SubprocVecEnv",
"for",
"Gym",
"Environments",
"."
] | e6efb0d8297ec38d704a3110b5d6ed74d09a05e3 | https://github.com/keras-rl/keras-rl/blob/e6efb0d8297ec38d704a3110b5d6ed74d09a05e3/rl/common/cmd_util.py#L7-L22 |
29,888 | awslabs/aws-sam-cli | samcli/commands/local/cli_common/options.py | invoke_common_options | def invoke_common_options(f):
"""
Common CLI options shared by "local invoke" and "local start-api" commands
:param f: Callback passed by Click
"""
invoke_options = [
template_click_option(),
click.option('--env-vars', '-n',
type=click.Path(exists=True),
... | python | def invoke_common_options(f):
"""
Common CLI options shared by "local invoke" and "local start-api" commands
:param f: Callback passed by Click
"""
invoke_options = [
template_click_option(),
click.option('--env-vars', '-n',
type=click.Path(exists=True),
... | [
"def",
"invoke_common_options",
"(",
"f",
")",
":",
"invoke_options",
"=",
"[",
"template_click_option",
"(",
")",
",",
"click",
".",
"option",
"(",
"'--env-vars'",
",",
"'-n'",
",",
"type",
"=",
"click",
".",
"Path",
"(",
"exists",
"=",
"True",
")",
","... | Common CLI options shared by "local invoke" and "local start-api" commands
:param f: Callback passed by Click | [
"Common",
"CLI",
"options",
"shared",
"by",
"local",
"invoke",
"and",
"local",
"start",
"-",
"api",
"commands"
] | c05af5e7378c6f05f7d82ad3f0bca17204177db6 | https://github.com/awslabs/aws-sam-cli/blob/c05af5e7378c6f05f7d82ad3f0bca17204177db6/samcli/commands/local/cli_common/options.py#L73-L130 |
29,889 | awslabs/aws-sam-cli | samcli/commands/_utils/options.py | template_click_option | def template_click_option(include_build=True):
"""
Click Option for template option
"""
return click.option('--template', '-t',
default=_TEMPLATE_OPTION_DEFAULT_VALUE,
type=click.Path(),
envvar="SAM_TEMPLATE_FILE",
... | python | def template_click_option(include_build=True):
"""
Click Option for template option
"""
return click.option('--template', '-t',
default=_TEMPLATE_OPTION_DEFAULT_VALUE,
type=click.Path(),
envvar="SAM_TEMPLATE_FILE",
... | [
"def",
"template_click_option",
"(",
"include_build",
"=",
"True",
")",
":",
"return",
"click",
".",
"option",
"(",
"'--template'",
",",
"'-t'",
",",
"default",
"=",
"_TEMPLATE_OPTION_DEFAULT_VALUE",
",",
"type",
"=",
"click",
".",
"Path",
"(",
")",
",",
"en... | Click Option for template option | [
"Click",
"Option",
"for",
"template",
"option"
] | c05af5e7378c6f05f7d82ad3f0bca17204177db6 | https://github.com/awslabs/aws-sam-cli/blob/c05af5e7378c6f05f7d82ad3f0bca17204177db6/samcli/commands/_utils/options.py#L73-L83 |
29,890 | awslabs/aws-sam-cli | samcli/lib/utils/tar.py | create_tarball | def create_tarball(tar_paths):
"""
Context Manger that creates the tarball of the Docker Context to use for building the image
Parameters
----------
tar_paths dict(str, str)
Key representing a full path to the file or directory and the Value representing the path within the tarball
Yie... | python | def create_tarball(tar_paths):
"""
Context Manger that creates the tarball of the Docker Context to use for building the image
Parameters
----------
tar_paths dict(str, str)
Key representing a full path to the file or directory and the Value representing the path within the tarball
Yie... | [
"def",
"create_tarball",
"(",
"tar_paths",
")",
":",
"tarballfile",
"=",
"TemporaryFile",
"(",
")",
"with",
"tarfile",
".",
"open",
"(",
"fileobj",
"=",
"tarballfile",
",",
"mode",
"=",
"'w'",
")",
"as",
"archive",
":",
"for",
"path_on_system",
",",
"path_... | Context Manger that creates the tarball of the Docker Context to use for building the image
Parameters
----------
tar_paths dict(str, str)
Key representing a full path to the file or directory and the Value representing the path within the tarball
Yields
------
The tarball file | [
"Context",
"Manger",
"that",
"creates",
"the",
"tarball",
"of",
"the",
"Docker",
"Context",
"to",
"use",
"for",
"building",
"the",
"image"
] | c05af5e7378c6f05f7d82ad3f0bca17204177db6 | https://github.com/awslabs/aws-sam-cli/blob/c05af5e7378c6f05f7d82ad3f0bca17204177db6/samcli/lib/utils/tar.py#L11-L37 |
29,891 | awslabs/aws-sam-cli | samcli/commands/local/lib/local_lambda_service.py | LocalLambdaService.start | def start(self):
"""
Creates and starts the Local Lambda Invoke service. This method will block until the service is stopped
manually using an interrupt. After the service is started, callers can make HTTP requests to the endpoint
to invoke the Lambda function and receive a response.
... | python | def start(self):
"""
Creates and starts the Local Lambda Invoke service. This method will block until the service is stopped
manually using an interrupt. After the service is started, callers can make HTTP requests to the endpoint
to invoke the Lambda function and receive a response.
... | [
"def",
"start",
"(",
"self",
")",
":",
"# We care about passing only stderr to the Service and not stdout because stdout from Docker container",
"# contains the response to the API which is sent out as HTTP response. Only stderr needs to be printed",
"# to the console or a log file. stderr from Dock... | Creates and starts the Local Lambda Invoke service. This method will block until the service is stopped
manually using an interrupt. After the service is started, callers can make HTTP requests to the endpoint
to invoke the Lambda function and receive a response.
NOTE: This is a blocking call t... | [
"Creates",
"and",
"starts",
"the",
"Local",
"Lambda",
"Invoke",
"service",
".",
"This",
"method",
"will",
"block",
"until",
"the",
"service",
"is",
"stopped",
"manually",
"using",
"an",
"interrupt",
".",
"After",
"the",
"service",
"is",
"started",
"callers",
... | c05af5e7378c6f05f7d82ad3f0bca17204177db6 | https://github.com/awslabs/aws-sam-cli/blob/c05af5e7378c6f05f7d82ad3f0bca17204177db6/samcli/commands/local/lib/local_lambda_service.py#L35-L58 |
29,892 | awslabs/aws-sam-cli | samcli/commands/local/lib/sam_function_provider.py | SamFunctionProvider._extract_sam_function_codeuri | def _extract_sam_function_codeuri(name, resource_properties, code_property_key):
"""
Extracts the SAM Function CodeUri from the Resource Properties
Parameters
----------
name str
LogicalId of the resource
resource_properties dict
Dictionary repres... | python | def _extract_sam_function_codeuri(name, resource_properties, code_property_key):
"""
Extracts the SAM Function CodeUri from the Resource Properties
Parameters
----------
name str
LogicalId of the resource
resource_properties dict
Dictionary repres... | [
"def",
"_extract_sam_function_codeuri",
"(",
"name",
",",
"resource_properties",
",",
"code_property_key",
")",
":",
"codeuri",
"=",
"resource_properties",
".",
"get",
"(",
"code_property_key",
",",
"SamFunctionProvider",
".",
"_DEFAULT_CODEURI",
")",
"# CodeUri can be a ... | Extracts the SAM Function CodeUri from the Resource Properties
Parameters
----------
name str
LogicalId of the resource
resource_properties dict
Dictionary representing the Properties of the Resource
code_property_key str
Property Key of the c... | [
"Extracts",
"the",
"SAM",
"Function",
"CodeUri",
"from",
"the",
"Resource",
"Properties"
] | c05af5e7378c6f05f7d82ad3f0bca17204177db6 | https://github.com/awslabs/aws-sam-cli/blob/c05af5e7378c6f05f7d82ad3f0bca17204177db6/samcli/commands/local/lib/sam_function_provider.py#L138-L163 |
29,893 | awslabs/aws-sam-cli | samcli/commands/local/lib/sam_function_provider.py | SamFunctionProvider._extract_lambda_function_code | def _extract_lambda_function_code(resource_properties, code_property_key):
"""
Extracts the Lambda Function Code from the Resource Properties
Parameters
----------
resource_properties dict
Dictionary representing the Properties of the Resource
code_property_k... | python | def _extract_lambda_function_code(resource_properties, code_property_key):
"""
Extracts the Lambda Function Code from the Resource Properties
Parameters
----------
resource_properties dict
Dictionary representing the Properties of the Resource
code_property_k... | [
"def",
"_extract_lambda_function_code",
"(",
"resource_properties",
",",
"code_property_key",
")",
":",
"codeuri",
"=",
"resource_properties",
".",
"get",
"(",
"code_property_key",
",",
"SamFunctionProvider",
".",
"_DEFAULT_CODEURI",
")",
"if",
"isinstance",
"(",
"codeu... | Extracts the Lambda Function Code from the Resource Properties
Parameters
----------
resource_properties dict
Dictionary representing the Properties of the Resource
code_property_key str
Property Key of the code on the Resource
Returns
-------
... | [
"Extracts",
"the",
"Lambda",
"Function",
"Code",
"from",
"the",
"Resource",
"Properties"
] | c05af5e7378c6f05f7d82ad3f0bca17204177db6 | https://github.com/awslabs/aws-sam-cli/blob/c05af5e7378c6f05f7d82ad3f0bca17204177db6/samcli/commands/local/lib/sam_function_provider.py#L195-L217 |
29,894 | awslabs/aws-sam-cli | samcli/commands/local/lib/sam_function_provider.py | SamFunctionProvider._parse_layer_info | def _parse_layer_info(list_of_layers, resources):
"""
Creates a list of Layer objects that are represented by the resources and the list of layers
Parameters
----------
list_of_layers List(str)
List of layers that are defined within the Layers Property on a function
... | python | def _parse_layer_info(list_of_layers, resources):
"""
Creates a list of Layer objects that are represented by the resources and the list of layers
Parameters
----------
list_of_layers List(str)
List of layers that are defined within the Layers Property on a function
... | [
"def",
"_parse_layer_info",
"(",
"list_of_layers",
",",
"resources",
")",
":",
"layers",
"=",
"[",
"]",
"for",
"layer",
"in",
"list_of_layers",
":",
"# If the layer is a string, assume it is the arn",
"if",
"isinstance",
"(",
"layer",
",",
"six",
".",
"string_types"... | Creates a list of Layer objects that are represented by the resources and the list of layers
Parameters
----------
list_of_layers List(str)
List of layers that are defined within the Layers Property on a function
resources dict
The Resources dictionary defined in... | [
"Creates",
"a",
"list",
"of",
"Layer",
"objects",
"that",
"are",
"represented",
"by",
"the",
"resources",
"and",
"the",
"list",
"of",
"layers"
] | c05af5e7378c6f05f7d82ad3f0bca17204177db6 | https://github.com/awslabs/aws-sam-cli/blob/c05af5e7378c6f05f7d82ad3f0bca17204177db6/samcli/commands/local/lib/sam_function_provider.py#L220-L270 |
29,895 | awslabs/aws-sam-cli | samcli/local/lambdafn/env_vars.py | EnvironmentVariables.resolve | def resolve(self):
"""
Resolves the values from different sources and returns a dict of environment variables to use when running
the function locally.
:return dict: Dict where key is the variable name and value is the value of the variable. Both key and values
are strings
... | python | def resolve(self):
"""
Resolves the values from different sources and returns a dict of environment variables to use when running
the function locally.
:return dict: Dict where key is the variable name and value is the value of the variable. Both key and values
are strings
... | [
"def",
"resolve",
"(",
"self",
")",
":",
"# AWS_* variables must always be passed to the function, but user has the choice to override them",
"result",
"=",
"self",
".",
"_get_aws_variables",
"(",
")",
"# Default value for the variable gets lowest priority",
"for",
"name",
",",
"... | Resolves the values from different sources and returns a dict of environment variables to use when running
the function locally.
:return dict: Dict where key is the variable name and value is the value of the variable. Both key and values
are strings | [
"Resolves",
"the",
"values",
"from",
"different",
"sources",
"and",
"returns",
"a",
"dict",
"of",
"environment",
"variables",
"to",
"use",
"when",
"running",
"the",
"function",
"locally",
"."
] | c05af5e7378c6f05f7d82ad3f0bca17204177db6 | https://github.com/awslabs/aws-sam-cli/blob/c05af5e7378c6f05f7d82ad3f0bca17204177db6/samcli/local/lambdafn/env_vars.py#L77-L104 |
29,896 | awslabs/aws-sam-cli | samcli/local/lambdafn/env_vars.py | EnvironmentVariables._stringify_value | def _stringify_value(self, value):
"""
This method stringifies values of environment variables. If the value of the method is a list or dictionary,
then this method will replace it with empty string. Values of environment variables in Lambda must be a string.
List or dictionary usually m... | python | def _stringify_value(self, value):
"""
This method stringifies values of environment variables. If the value of the method is a list or dictionary,
then this method will replace it with empty string. Values of environment variables in Lambda must be a string.
List or dictionary usually m... | [
"def",
"_stringify_value",
"(",
"self",
",",
"value",
")",
":",
"# List/dict/None values are replaced with a blank",
"if",
"isinstance",
"(",
"value",
",",
"(",
"dict",
",",
"list",
",",
"tuple",
")",
")",
"or",
"value",
"is",
"None",
":",
"result",
"=",
"se... | This method stringifies values of environment variables. If the value of the method is a list or dictionary,
then this method will replace it with empty string. Values of environment variables in Lambda must be a string.
List or dictionary usually means they are intrinsic functions which have not been r... | [
"This",
"method",
"stringifies",
"values",
"of",
"environment",
"variables",
".",
"If",
"the",
"value",
"of",
"the",
"method",
"is",
"a",
"list",
"or",
"dictionary",
"then",
"this",
"method",
"will",
"replace",
"it",
"with",
"empty",
"string",
".",
"Values",... | c05af5e7378c6f05f7d82ad3f0bca17204177db6 | https://github.com/awslabs/aws-sam-cli/blob/c05af5e7378c6f05f7d82ad3f0bca17204177db6/samcli/local/lambdafn/env_vars.py#L175-L204 |
29,897 | awslabs/aws-sam-cli | samcli/local/docker/container.py | Container.delete | def delete(self):
"""
Removes a container that was created earlier.
"""
if not self.is_created():
LOG.debug("Container was not created. Skipping deletion")
return
try:
self.docker_client.containers\
.get(self.id)\
... | python | def delete(self):
"""
Removes a container that was created earlier.
"""
if not self.is_created():
LOG.debug("Container was not created. Skipping deletion")
return
try:
self.docker_client.containers\
.get(self.id)\
... | [
"def",
"delete",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_created",
"(",
")",
":",
"LOG",
".",
"debug",
"(",
"\"Container was not created. Skipping deletion\"",
")",
"return",
"try",
":",
"self",
".",
"docker_client",
".",
"containers",
".",
"get... | Removes a container that was created earlier. | [
"Removes",
"a",
"container",
"that",
"was",
"created",
"earlier",
"."
] | c05af5e7378c6f05f7d82ad3f0bca17204177db6 | https://github.com/awslabs/aws-sam-cli/blob/c05af5e7378c6f05f7d82ad3f0bca17204177db6/samcli/local/docker/container.py#L139-L163 |
29,898 | awslabs/aws-sam-cli | samcli/local/docker/container.py | Container.start | def start(self, input_data=None):
"""
Calls Docker API to start the container. The container must be created at the first place to run.
It waits for the container to complete, fetches both stdout and stderr logs and returns through the
given streams.
Parameters
---------... | python | def start(self, input_data=None):
"""
Calls Docker API to start the container. The container must be created at the first place to run.
It waits for the container to complete, fetches both stdout and stderr logs and returns through the
given streams.
Parameters
---------... | [
"def",
"start",
"(",
"self",
",",
"input_data",
"=",
"None",
")",
":",
"if",
"input_data",
":",
"raise",
"ValueError",
"(",
"\"Passing input through container's stdin is not supported\"",
")",
"if",
"not",
"self",
".",
"is_created",
"(",
")",
":",
"raise",
"Runt... | Calls Docker API to start the container. The container must be created at the first place to run.
It waits for the container to complete, fetches both stdout and stderr logs and returns through the
given streams.
Parameters
----------
input_data
Optional. Input data ... | [
"Calls",
"Docker",
"API",
"to",
"start",
"the",
"container",
".",
"The",
"container",
"must",
"be",
"created",
"at",
"the",
"first",
"place",
"to",
"run",
".",
"It",
"waits",
"for",
"the",
"container",
"to",
"complete",
"fetches",
"both",
"stdout",
"and",
... | c05af5e7378c6f05f7d82ad3f0bca17204177db6 | https://github.com/awslabs/aws-sam-cli/blob/c05af5e7378c6f05f7d82ad3f0bca17204177db6/samcli/local/docker/container.py#L165-L187 |
29,899 | awslabs/aws-sam-cli | samcli/local/docker/container.py | Container._write_container_output | def _write_container_output(output_itr, stdout=None, stderr=None):
"""
Based on the data returned from the Container output, via the iterator, write it to the appropriate streams
Parameters
----------
output_itr: Iterator
Iterator returned by the Docker Attach comman... | python | def _write_container_output(output_itr, stdout=None, stderr=None):
"""
Based on the data returned from the Container output, via the iterator, write it to the appropriate streams
Parameters
----------
output_itr: Iterator
Iterator returned by the Docker Attach comman... | [
"def",
"_write_container_output",
"(",
"output_itr",
",",
"stdout",
"=",
"None",
",",
"stderr",
"=",
"None",
")",
":",
"# Iterator returns a tuple of (frame_type, data) where the frame type determines which stream we write output",
"# to",
"for",
"frame_type",
",",
"data",
"i... | Based on the data returned from the Container output, via the iterator, write it to the appropriate streams
Parameters
----------
output_itr: Iterator
Iterator returned by the Docker Attach command
stdout: samcli.lib.utils.stream_writer.StreamWriter, optional
Str... | [
"Based",
"on",
"the",
"data",
"returned",
"from",
"the",
"Container",
"output",
"via",
"the",
"iterator",
"write",
"it",
"to",
"the",
"appropriate",
"streams"
] | c05af5e7378c6f05f7d82ad3f0bca17204177db6 | https://github.com/awslabs/aws-sam-cli/blob/c05af5e7378c6f05f7d82ad3f0bca17204177db6/samcli/local/docker/container.py#L229-L258 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.