本文整理汇总了Python中tornado.ioloop.IOLoop方法的典型用法代码示例。如果您正苦于以下问题:Python ioloop.IOLoop方法的具体用法?Python ioloop.IOLoop怎么用?Python ioloop.IOLoop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.ioloop
的用法示例。
在下文中一共展示了ioloop.IOLoop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def start(io_loop=None, check_time=500):
"""Begins watching source files for changes.
.. versionchanged:: 4.1
The ``io_loop`` argument is deprecated.
"""
io_loop = io_loop or ioloop.IOLoop.current()
if io_loop in _io_loops:
return
_io_loops[io_loop] = True
if len(_io_loops) > 1:
gen_log.warning("tornado.autoreload started more than once in the same process")
if _has_execv:
add_reload_hook(functools.partial(io_loop.close, all_fds=True))
modify_times = {}
callback = functools.partial(_reload_on_update, modify_times)
scheduler = ioloop.PeriodicCallback(callback, check_time, io_loop=io_loop)
scheduler.start()
示例2: start
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def start(check_time: int = 500) -> None:
"""Begins watching source files for changes.
.. versionchanged:: 5.0
The ``io_loop`` argument (deprecated since version 4.1) has been removed.
"""
io_loop = ioloop.IOLoop.current()
if io_loop in _io_loops:
return
_io_loops[io_loop] = True
if len(_io_loops) > 1:
gen_log.warning("tornado.autoreload started more than once in the same process")
modify_times = {} # type: Dict[str, float]
callback = functools.partial(_reload_on_update, modify_times)
scheduler = ioloop.PeriodicCallback(callback, check_time)
scheduler.start()
示例3: stop
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def stop(self, _arg: Any = None, **kwargs: Any) -> None:
"""Stops the `.IOLoop`, causing one pending (or future) call to `wait()`
to return.
Keyword arguments or a single positional argument passed to `stop()` are
saved and will be returned by `wait()`.
.. deprecated:: 5.1
`stop` and `wait` are deprecated; use ``@gen_test`` instead.
"""
assert _arg is None or not kwargs
self.__stop_args = kwargs or _arg
if self.__running:
self.io_loop.stop()
self.__running = False
self.__stopped = True
示例4: setUp
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def setUp(self):
self.server_ioloop = IOLoop()
event = threading.Event()
@gen.coroutine
def init_server():
sock, self.port = bind_unused_port()
app = Application([("/", HelloWorldHandler)])
self.server = HTTPServer(app)
self.server.add_socket(sock)
event.set()
def start():
self.server_ioloop.run_sync(init_server)
self.server_ioloop.start()
self.server_thread = threading.Thread(target=start)
self.server_thread.start()
event.wait()
self.http_client = HTTPClient()
示例5: tearDown
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def tearDown(self):
def stop_server():
self.server.stop()
# Delay the shutdown of the IOLoop by several iterations because
# the server may still have some cleanup work left when
# the client finishes with the response (this is noticeable
# with http/2, which leaves a Future with an unexamined
# StreamClosedError on the loop).
@gen.coroutine
def slow_stop():
yield self.server.close_all_connections()
# The number of iterations is difficult to predict. Typically,
# one is sufficient, although sometimes it needs more.
for i in range(5):
yield
self.server_ioloop.stop()
self.server_ioloop.add_callback(slow_stop)
self.server_ioloop.add_callback(stop_server)
self.server_thread.join()
self.http_client.close()
self.server_ioloop.close(all_fds=True)
示例6: with_ioloop
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def with_ioloop(method, expect_success=True):
"""decorator for running tests with an IOLoop"""
def test_method(self):
r = method(self)
loop = self.io_loop
if expect_success:
self.pullstream.on_recv(self.on_message_succeed)
else:
self.pullstream.on_recv(self.on_message_fail)
loop.call_later(1, self.attempt_connection)
loop.call_later(1.2, self.send_msg)
if expect_success:
loop.call_later(2, self.on_test_timeout_fail)
else:
loop.call_later(2, self.on_test_timeout_succeed)
loop.start()
if self.fail_msg:
self.fail(self.fail_msg)
return r
return test_method
示例7: start
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def start(check_time=500):
"""Begins watching source files for changes.
.. versionchanged:: 5.0
The ``io_loop`` argument (deprecated since version 4.1) has been removed.
"""
io_loop = ioloop.IOLoop.current()
if io_loop in _io_loops:
return
_io_loops[io_loop] = True
if len(_io_loops) > 1:
gen_log.warning("tornado.autoreload started more than once in the same process")
modify_times = {}
callback = functools.partial(_reload_on_update, modify_times)
scheduler = ioloop.PeriodicCallback(callback, check_time)
scheduler.start()
示例8: stop
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def stop(self, _arg=None, **kwargs):
"""Stops the `.IOLoop`, causing one pending (or future) call to `wait()`
to return.
Keyword arguments or a single positional argument passed to `stop()` are
saved and will be returned by `wait()`.
.. deprecated:: 5.1
`stop` and `wait` are deprecated; use ``@gen_test`` instead.
"""
assert _arg is None or not kwargs
self.__stop_args = kwargs or _arg
if self.__running:
self.io_loop.stop()
self.__running = False
self.__stopped = True
示例9: start
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def start(io_loop=None, check_time=500):
"""Begins watching source files for changes.
.. versionchanged:: 4.1
The ``io_loop`` argument is deprecated.
"""
io_loop = io_loop or ioloop.IOLoop.current()
if io_loop in _io_loops:
return
_io_loops[io_loop] = True
if len(_io_loops) > 1:
gen_log.warning("tornado.autoreload started more than once in the same process")
modify_times = {}
callback = functools.partial(_reload_on_update, modify_times)
scheduler = ioloop.PeriodicCallback(callback, check_time, io_loop=io_loop)
scheduler.start()
示例10: _testReadWrite
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def _testReadWrite(self):
"""
In this test the writer writes an 'x' to its fd. The reader
reads it, check the value and ends the test.
"""
self.shouldWrite = True
def checkReadInput(fd):
self.assertEquals(fd.read(), 'x')
self._reactor.stop()
def writeOnce(fd):
if self.shouldWrite:
self.shouldWrite = False
fd.write('x')
self._reader = Reader(self._p1, checkReadInput)
self._writer = Writer(self._p2, writeOnce)
self._reactor.addWriter(self._writer)
# Test that adding the reader twice adds it only once to
# IOLoop.
self._reactor.addReader(self._reader)
self._reactor.addReader(self._reader)
示例11: test_git_ref
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def test_git_ref(url, unresolved_ref, resolved_ref):
spec = '{}/{}'.format(
quote(url, safe=''),
quote(unresolved_ref)
)
provider = GitRepoProvider(spec=spec)
slug = provider.get_build_slug()
assert slug == url
full_url = provider.get_repo_url()
assert full_url == url
ref = IOLoop().run_sync(provider.get_resolved_ref)
assert ref == resolved_ref
ref_url = IOLoop().run_sync(provider.get_resolved_ref_url)
assert ref_url == full_url
resolved_spec = IOLoop().run_sync(provider.get_resolved_spec)
assert resolved_spec == quote(url, safe='') + f'/{resolved_ref}'
示例12: test_gitlab_ref
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def test_gitlab_ref():
namespace = 'gitlab-org/gitlab-foss'
spec = '{}/{}'.format(
quote(namespace, safe=''),
quote('v10.0.6')
)
provider = GitLabRepoProvider(spec=spec)
slug = provider.get_build_slug()
assert slug == 'gitlab_-org-gitlab_-foss'
full_url = provider.get_repo_url()
assert full_url == f'https://gitlab.com/{namespace}.git'
ref = IOLoop().run_sync(provider.get_resolved_ref)
assert ref == 'b3344b7f17c335a817c5d7608c5e47fd7cabc023'
ref_url = IOLoop().run_sync(provider.get_resolved_ref_url)
assert ref_url == f'https://gitlab.com/{namespace}/tree/{ref}'
resolved_spec = IOLoop().run_sync(provider.get_resolved_spec)
assert resolved_spec == quote(namespace, safe='') + f'/{ref}'
示例13: run
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def run(self, quiet=None, server=''):
""" Start the tornado server, run forever.
'quiet' and 'server' arguments are no longer used, they are keep only for backward compatibility
"""
try:
loop = IOLoop()
http_server = HTTPServer(WSGIContainer(self.app))
http_server.listen(self.port)
loop.start()
except socket.error as serr:
# Re raise the socket error if not "[Errno 98] Address already in use"
if serr.errno != errno.EADDRINUSE:
raise serr
else:
logger.warning("""The webserver port {} is already used.
The SnapRobotServer is maybe already run or another software use this port.""".format(self.port))
示例14: startServer
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def startServer(self):
self.server = Server(
{
"/devices": self._dev_app_ref(),
"/trends": self._trends_app_ref(),
"/notes": self._notes_app_ref(),
},
io_loop=IOLoop(),
allow_websocket_origin=[
"{}:8111".format(self.IP),
"{}:5006".format(self.IP),
"{}:8111".format("localhost"),
"{}:5006".format("localhost"),
],
)
self.server.start()
self.server.io_loop.start()
示例15: test_server_static_dirs
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import IOLoop [as 别名]
def test_server_static_dirs():
html = Markdown('# Title')
loop = IOLoop()
server = StoppableThread(
target=html._get_server, io_loop=loop,
args=(5008, None, None, loop, False, True, None, False, None),
kwargs=dict(static_dirs={'tests': os.path.dirname(__file__)}))
server.start()
# Wait for server to start
time.sleep(1)
r = requests.get("http://localhost:5008/tests/test_server.py")
with open(__file__) as f:
assert f.read() == r.content.decode('utf-8')
server.stop()