ES7 -> python side by side?

Hello. Need to quickly learn Python, but rather his ability to async. Worked with JS ES7, async/await including, so I'll ask: is there a side by side comparison ES7 code in JS and Python? Thus to understand the language will be much easier.

Thanks in advance.
June 8th 19 at 17:12
2 answers
June 8th 19 at 17:14
Solution
Thank you very much, but most importantly - async was not described. For example, in JS in 99% of cases, the functions from asynchronous writing, if required. Using async/await, the promises, Kabakov or anything else. In python most of the code - synchronous, even where there is clearly need async. Most likely it sounds stupid for someone who knows Python, but how I can adequately convert all synchronous methods asynchronous?

As a simple example using this function. Do a project with 500 stars on the Gita "forgot" to write an asynchronous version of the functions? It can not be that they are not wanted. Most likely I'm blunt and ask for help.

Thank you. - Gerda57 commented on June 8th 19 at 17:17
,
Why there is async?

limit - Default is 500; 500 max. - marilyne_Roh commented on June 8th 19 at 17:20
in the sense of what? This is an http request. Write the bot, for example, which simultaneously monitors a dozen orders, so everytime you lock the thread?

About the limit is not understood. - Gerda57 commented on June 8th 19 at 17:23
and why do they need the asynchronous version of the functions? Python supports multi-threading if calling code will need to make an asynchronous call, the programmer is there will cause him accordingly. - cortney.Kuhic commented on June 8th 19 at 17:26
there comes back the sheet from up to 500 elements

Account trade list (USER_DATA)

https://github.com/binance-exchange/binance-offici... - marilyne_Roh commented on June 8th 19 at 17:29
I've seen hacks that can be used to run synchronous functions asynchronously, but it said that greedy runs as a separate process Python that is not exactly what I need. Iskrenne don't understand how you can ask "why the asynchronous version" for the http request.. if that where we send the request, the server just salawaat (say), then the stream just freeze for 5 seconds? This is complete nonsense.

Sorry for topescu, but as a JS dev I'm sure there something not understand( - Gerda57 commented on June 8th 19 at 17:32
, no matter what PL you develop

In the case of freezing - you may have to deal with the situation of underload data

If you can make it, you can't add async to a function is not difficult - marilyne_Roh commented on June 8th 19 at 17:35
logical. But what does this have to do with async? The method is taken as an example, mostly will be used create_order, cancel_order in large quantities and in parallel. I don't want every function call starts a separate process, and don't want one query block the entire flow. - Gerda57 commented on June 8th 19 at 17:38
,
So you should rewrite Libu in Java and to warm it with data
How to do in the adult trading

Or you can rewrite Libu using https://docs.python.org/3/library/asyncio-task.html

In this case, I don't see any problems - marilyne_Roh commented on June 8th 19 at 17:41
that is , in any case will have to be rewritten, right?) Yes, I realize that such hacks are not suitable for normal trading. We are now working on a prototype, so not much go into details and to compromise. - Gerda57 commented on June 8th 19 at 17:44
,
no idea

I have no expertise in trading

But doing the trading in JAPANESE, which does not guarantee timings is insane - marilyne_Roh commented on June 8th 19 at 17:47
create usually are not processes, but threads. They are lightweight. That is, in a single process of Python is somewhat parallel streams. - cortney.Kuhic commented on June 8th 19 at 17:50
, в любом случае в разы сложнее чем аналогичный код на JS. Я знаю, что это тоже не лучший выбор, но все же. - Gerda57 commented on June 8th 19 at 17:53
timings in the strategies we use are not important. - Gerda57 commented on June 8th 19 at 17:56
no , not harder

Read the link I gave - marilyne_Roh commented on June 8th 19 at 17:59
,
It can not be that they are not wanted


the timings in the strategies we use are not important.


I'm sorry, but then your comment to me does not understand - marilyne_Roh commented on June 8th 19 at 18:02
read. I see that I can wait for the result of the asynchronous call, using the chain of the future, but this is working with existing asynchronous code. - Gerda57 commented on June 8th 19 at 18:05
when you mentioned the timings, I replied referring to the speed of the program and not blocking flow) - Gerda57 commented on June 8th 19 at 18:08
and as the timings in one case are different from the timings of the other? - marilyne_Roh commented on June 8th 19 at 18:11
when one query, else "freezes". In this case, the delay is huge. In the case of "timings" in my understanding, the same logic written in different ways to work out at different speeds (timings) - Gerda57 commented on June 8th 19 at 18:14
,
Timeout after which will be caused by eksepsi configured
Architectural no one will post the parser and script Analytics in a single thread / script
Script Analytics still need to wait for actual information - it needs to be frozen anyway - marilyne_Roh commented on June 8th 19 at 18:17
in JS there is a simple asynchrony. Yes, it works in a single thread, but it's a lot and is not required.

Analytics there are quite elementary, and the problem is not intelligence at all, even if she was in a separate thread. - Gerda57 commented on June 8th 19 at 18:20
in Python there is a simple async - marilyne_Roh commented on June 8th 19 at 18:23
@Alex_Wells
I see that I can wait for the result of the asynchronous call, using the chain of the future, but this is working with existing asynchronous code.


Cause executor.submit the desired function, and he wraps her in the future. What could be simpler.

The difference with JS is that in languages that support multithreading (and this Java and .NET, and Python and Ruby and C++, etc.) decided to perform synchronous calls, giving care of the parallelization at the mercy of the programmer. Because that knows when and what tasks to thread. - cortney.Kuhic commented on June 8th 19 at 18:26
June 8th 19 at 17:16
async/await was introduced in version 3.5. For http there is a separate aiohttp.
https://asyncio.readthedocs.io/en/latest/
https://aiohttp.readthedocs.io/en/stable/
Looks like this:

ASYNCIO:
import asyncio

async def say(what, when):
 await asyncio.sleep(when)
print(what)

async def stop_after(loop, when):
 await asyncio.sleep(when)
loop.stop()


loop = asyncio.get_event_loop()

loop.create_task(say('first hello', 2))
loop.create_task(say('hello second', 1))
loop.create_task(say('third hello', 4))
loop.create_task(stop_after(loop, 3))

loop.run_forever()
loop.close()


AIOHTTP CLIENT:
import aiohttp
import asyncio
import async_timeout

async def fetch(session, url):
 with async_timeout.timeout(10):
 async with the session.get(url) as response:
 return await response.text()

async def main():
 async with aiohttp.ClientSession() as session:
 html = await fetch(session, 'http://python.org')
print(html)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())


AIOHTTP SERVER:
from aiohttp import web

async def handle(request):
 name = request.match_info.get('name', "Anonymous")
 text = "Hello," + name
 return web.Response(text=text)

app = web.Application()
app.router.add_get('/', handle)
app.router.add_get('/{name}', handle)

web.run_app(app)
Thank you, that is painted, but I have the option already available synchronous library and write it from scratch doesn't make sense. Moved to JS. - Gerda57 commented on June 8th 19 at 17:19

Find more questions by tags JavaScriptPython