本文整理汇总了Python中trio.run方法的典型用法代码示例。如果您正苦于以下问题:Python trio.run方法的具体用法?Python trio.run怎么用?Python trio.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trio
的用法示例。
在下文中一共展示了trio.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: agent
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def agent(options=None):
import trio
from burpui.engines.agent import BUIAgent as Agent
from burpui.utils import lookup_file
if not options:
options, _ = parse_args(mode=False, name='bui-agent')
conf = ['buiagent.cfg', 'buiagent.sample.cfg']
if options.config:
conf = lookup_file(options.config, guess=False)
else:
conf = lookup_file(conf)
check_config(conf)
agent = Agent(conf, options.log, options.logfile)
trio.run(agent.run)
示例2: monitor
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def monitor(options=None):
import trio
from burpui.engines.monitor import MonitorPool
from burpui.utils import lookup_file
if not options:
options, _ = parse_args(mode=False, name='bui-agent')
conf = ['buimonitor.cfg', 'buimonitor.sample.cfg']
if options.config:
conf = lookup_file(options.config, guess=False)
else:
conf = lookup_file(conf)
check_config(conf)
monitor = MonitorPool(conf, options.log, options.logfile)
trio.run(monitor.run)
示例3: restore_files
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def restore_files(self, name=None, backup=None, files=None, strip=None,
archive='zip', password=None, agent=None):
return trio.run(self._async_restore_files, name, backup, files, strip, archive, password, agent)
# Same as in Burp1 backend
# def read_conf_cli(self, agent=None):
# def read_conf_srv(self, agent=None):
# def store_conf_cli(self, data, agent=None):
# def store_conf_srv(self, data, agent=None):
# def get_parser_attr(self, attr=None, agent=None):
# Make every "Burp" method async
示例4: monitor
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def monitor(options=None):
import trio
from burpui_monitor.engines.monitor import MonitorPool
from burpui_monitor.utils import lookup_file
if not options:
options = parse_args(name='bui-monitor')
conf = ['buimonitor.cfg', 'buimonitor.sample.cfg']
if options.config:
conf = lookup_file(options.config, guess=False)
else:
conf = lookup_file(conf)
check_config(conf)
monitor = MonitorPool(conf, options.log, options.logfile)
trio.run(monitor.run)
示例5: agent
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def agent(options=None):
import trio
from burpui_agent.engines.agent import BUIAgent as Agent
from burpui_agent.utils import lookup_file
from burpui_agent._compat import patch_json
patch_json()
if not options:
options = parse_args(name='bui-agent')
conf = ['buiagent.cfg', 'buiagent.sample.cfg']
if options.config:
conf = lookup_file(options.config, guess=False)
else:
conf = lookup_file(conf)
check_config(conf)
agent = Agent(conf, options.log, options.logfile)
trio.run(agent.run)
示例6: test_sans_io_exception
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def test_sans_io_exception():
class BrokenSender(AsyncHTTPSender):
async def send(self, request, **config):
raise ValueError("Broken")
async def __aexit__(self, exc_type, exc_value, traceback):
"""Raise any exception triggered within the runtime context."""
return None
pipeline = AsyncPipeline([SansIOHTTPPolicy()], BrokenSender())
req = ClientRequest('GET', '/')
with pytest.raises(ValueError):
await pipeline.run(req)
class SwapExec(SansIOHTTPPolicy):
def on_exception(self, requests, **kwargs):
exc_type, exc_value, exc_traceback = sys.exc_info()
raise NotImplementedError(exc_value)
pipeline = AsyncPipeline([SwapExec()], BrokenSender())
with pytest.raises(NotImplementedError):
await pipeline.run(req)
示例7: get_sign
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def get_sign(self, token, query):
'''使用拼装参数签名
post https://api.appsign.vip:2688/sign -->
{
"token":"TOKEN",
"query":"通过参数生成的加签字符串"
}
>>> data, res = trio.run(SignUtil().get_sign, 'aaa', {"aaa":"aaa"})
>>> print(res)
{'success': False, 'error': 'token is error'}
'''
assert isinstance(query, dict)
url = f"{_API}/sign"
resp = await self.s.post(url, json={"token": token, "query": params2str(query)}, verify=False)
logging.debug(f"post response from {url} is {resp} with body: {trim(resp.text)}")
return resp.json().get('data', {}), resp.json()
示例8: migrate
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def migrate(credentials_file, credentials_blob, table):
"""
Synchronizes the BigQuery table schema.
TABLE is a BigQuery table identifier of the form ProjectId.DataSetId.TableId.
"""
bq = _configure_bigquery(credentials_file, credentials_blob)
schema = json.loads(importlib_resources.read_text("linehaul", "schema.json"))
trio.run(migrate_, bq, table, schema)
示例9: serve
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def serve(
app: ASGIFramework,
config: Config,
*,
shutdown_trigger: Optional[Callable[..., Awaitable[None]]] = None,
task_status: trio._core._run._TaskStatus = trio.TASK_STATUS_IGNORED,
) -> None:
"""Serve an ASGI framework app given the config.
This allows for a programmatic way to serve an ASGI framework, it
can be used via,
.. code-block:: python
trio.run(partial(serve, app, config))
It is assumed that the event-loop is configured before calling
this function, therefore configuration values that relate to loop
setup or process setup are ignored.
Arguments:
app: The ASGI application to serve.
config: A Hypercorn configuration object.
shutdown_trigger: This should return to trigger a graceful
shutdown.
"""
if config.debug:
warnings.warn("The config `debug` has no affect when using serve", Warning)
if config.workers != 1:
warnings.warn("The config `workers` has no affect when using serve", Warning)
await worker_serve(app, config, shutdown_trigger=shutdown_trigger, task_status=task_status)
示例10: trio_worker
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def trio_worker(
config: Config, sockets: Optional[Sockets] = None, shutdown_event: Optional[EventType] = None
) -> None:
if sockets is not None:
for sock in sockets.secure_sockets:
sock.listen(config.backlog)
for sock in sockets.insecure_sockets:
sock.listen(config.backlog)
app = load_application(config.application_path)
shutdown_trigger = None
if shutdown_event is not None:
shutdown_trigger = partial(check_multiprocess_shutdown_event, shutdown_event, trio.sleep)
trio.run(partial(worker_serve, app, config, sockets=sockets, shutdown_trigger=shutdown_trigger))
示例11: trio_run
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def trio_run(async_fn, *args, use_asyncio=False, monitor_tasks=True):
if use_asyncio:
# trio_asyncio is an optional dependency
import trio_asyncio
return trio_asyncio.run(async_fn, *args)
instruments = (TaskMonitoringInstrument(),) if monitor_tasks else ()
return trio.run(async_fn, *args, instruments=instruments)
# MultiError handling
示例12: test_on_trio_loop_closed
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def test_on_trio_loop_closed(monkeypatch):
trio_loop_closed = threading.Event()
vanilla_trio_run = trio.run
def patched_trio_run(*args, **kwargs):
try:
vanilla_trio_run(*args, **kwargs)
finally:
trio_loop_closed.set()
monkeypatch.setattr("trio.run", patched_trio_run)
on_success = MagicMock(spec=ThreadSafeQtSignal, args_types=())
on_error_j1 = MagicMock(spec=ThreadSafeQtSignal, args_types=())
on_error_j2 = MagicMock(spec=ThreadSafeQtSignal, args_types=())
with run_trio_thread() as job_scheduler:
job1 = job_scheduler.submit_job(on_success, on_error_j1, trio.sleep_forever)
# Stop the trio loop
job_scheduler.stop()
trio_loop_closed.wait()
# Stop is idempotent
job_scheduler.stop()
# Cancelling job is still ok
job1.cancel_and_join()
on_success.emit.assert_not_called()
on_error_j1.emit.assert_called_once()
assert job1.status == "cancelled"
assert isinstance(job1.exc, trio.Cancelled)
# New jobs are directly cancelled
job2 = job_scheduler.submit_job(on_success, on_error_j2, lambda: None)
on_success.emit.assert_not_called()
on_error_j2.emit.assert_called_once()
assert job2.status == "cancelled"
assert isinstance(job2.exc, JobSchedulerNotAvailable)
示例13: smallcheck
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def smallcheck():
return trio.run(_do_check_new_version, gui_check_version_url, gui_check_version_api_url)
示例14: server
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def server(options=None, unknown=None):
from burpui.utils import lookup_file
if unknown is None:
unknown = []
if not options:
options, unknown = parse_args(mode=False)
env = os.environ
if options.config:
conf = lookup_file(options.config, guess=False)
else:
if 'BUI_CONFIG' in env:
conf = env['BUI_CONFIG']
else:
conf = lookup_file()
check_config(conf)
if os.path.isdir('burpui'):
env['FLASK_APP'] = 'burpui/cli.py'
else:
env['FLASK_APP'] = 'burpui.cli'
env['BUI_CONFIG'] = conf
env['BUI_VERBOSE'] = str(options.log)
if options.logfile:
env['BUI_LOGFILE'] = options.logfile
if options.debug:
env['BUI_DEBUG'] = '1'
env['FLASK_DEBUG'] = '1'
env['BUI_MODE'] = 'server'
args = [
'flask',
'run'
]
args += unknown
args += [x for x in options.remaining if x != '--']
os.execvpe(args[0], args, env)
示例15: batch_list_supported
# 需要导入模块: import trio [as 别名]
# 或者: from trio import run [as 别名]
def batch_list_supported(self):
if self._batch_list_supported is None:
self._batch_list_supported = json.loads(trio.run(self._async_request, 'batch_list_supported'))
return self._batch_list_supported