Example #1
0
def main(address='127.0.0.1', port=8888):

	port = int(port)
	loop = asyncio.get_event_loop()
	#init是协程,需要yield from或者类似run_until_complete这样的函数来驱动
	host = asyncio.run_until_complete(init(loop, address, port))

	try:
		loop.run_forever()
	except KeyboardInterrupt:
		pass

	loop.close()
Example #2
0
def main(address='127.0.0.1', port=2323):

	loop = asyncio.get_event_loop()
	#start_server返回协程,需要用yield from或者run_until_complete这样的函数来驱动
	coro = asyncio.start_server(loop)
	server = asyncio.run_until_complete(coro)

	try:
		loop.run_forever()
	except KeyboardInterrupty:
		pass

	server.close()
	loop.run_until_complete(server.wait_closed())
	loop.close()
Example #3
0
    """
    # Create Prompt.
    session = PromptSession("Say something: ")

    # Run echo loop. Read text from stdin, and reply it back.
    while True:
        try:
            result = await session.prompt_async()
            print('You said: "{0}"'.format(result))
        except (EOFError, KeyboardInterrupt):
            return


async def main():
    with patch_stdout():
        background_task = asyncio.create_task(print_counter())
        try:
            await interactive_shell()
        finally:
            background_task.cancel()
        print("Quitting event loop. Bye.")


if __name__ == "__main__":
    try:
        from asyncio import run
    except ImportError:
        asyncio.run_until_complete(main())
    else:
        asyncio.run(main())
Example #4
0
               limit=None):
        qs = {
            "search": name,
            "author": author,
            "category": category,
            "offset": offset,
            "limit": (deck_list_max if limit is None else limit)
        }
        req = yield from aiohtp.request("get", self.deck_list_url, params=qs)
        if req.status == 200:
            json = yield from req.json()
            return SearchReturn.from_json(json)
        elif req.status == 404:
            err = "Search query returned not found"
            raise SearchNotFoundError(err)
        else:
            err = "Error searching decks (code {})".format(req.status)
            raise SearchRetrievalError(err)

    def search_iter(self, name=None, author=None, category=None, offset=0,
                    limit=None):
        s = asyncio.run_until_complete(self.search(name, author, category,
                                                   offset, limit))

        while s.count > 0:
            yield s

            offset += s.count
            s = asyncio.run_until_complete(self.search(name, author, category,
                                                       offset, limit))
Example #5
0
def on_exit():
    print("Exiting...")
    asyncio.run_until_complete(bot.logout())
Example #6
0
'''

import asyncio

loop  = asyncio.get_event_loop()

@asyncio.coroutine
def hello():
  print 1
  yield from asyncio.sleep(3)
  print 'done'


asunc def hello2():
  print 1
  await asyncio.sleep(3)
  print 'done'

if  __name__ == '__main__'
  loop  = asyncio.run_until_complete( hello() )
  
  
  
'''
 heavy task
 - call await asyncio.sleep(0)
'''
  
  
Example #7
0
 def __exit__(self, exec_type, exc_value, traceback):
     self.ws.close()
     asyncio.run_until_complete(self.ws.wait_closed())
Example #8
0
        button_number = ws_json['data'][0]['button']
        button_state = ws_json['data'][0]['state']
        button_pressed(button_number, button_state)
        response = "Command Sent: "+ws_command

	#handle configuration edits here
    if (ws_json['type'] == 'configure'):
        update_config(ws_json['data'][0]['section'], ws_json['data'][0]['option'], ws_json['data'][0]['value'])
        print("Configuration Edited")
        response = "Config Edited"

    await websocket.send(response)
    await asyncio.sleep()

start_websocket_server = websockets.serve(hello, "192.168.2.2", 5678)


#############
# WEBSOCKET #
#############







asyncio.get_event_loop().run_until_complete(start_websocket_server)
asyncio.get_event_loop().run_forever()
asyncio.run_until_complete(buttons)