From 80bbc4ceec8d763531fa3668ce833eb39d22b62e Mon Sep 17 00:00:00 2001 From: bilalAlpaslan Date: Tue, 12 Apr 2022 19:31:18 +0300 Subject: [PATCH 1/7] turkish translate --- docs/tr/docs/async.md | 399 ++++++++++++++++++++++++++++++++++++++++++ docs/tr/mkdocs.yml | 1 + 2 files changed, 400 insertions(+) create mode 100644 docs/tr/docs/async.md diff --git a/docs/tr/docs/async.md b/docs/tr/docs/async.md new file mode 100644 index 0000000000000..af3b33cff371e --- /dev/null +++ b/docs/tr/docs/async.md @@ -0,0 +1,399 @@ +# Eşzamanlılık ve async / await + +*path operasyon fonksiyonu* için `async def`sözyazımı, asenkron kod, eşzamanlılık ve paralellik hakkında bazı bilgiler. + +## Aceleniz mi var? + +TL;DR: + +Eğer onları `await` ile çağırmanızı söyleyen üçüncü taraf bir kütüphane kullanıyorsanız, örneğin: + +```Python +results = await some_library() +``` + +O zaman *path operasyon fonksiyonunu* `async def` ile tanımlayın: + +```Python hl_lines="2" +@app.get('/') +async def read_results(): + results = await some_library() + return results +``` + +!!! not + `await` yalnızca `async def` ile tanımlanan fonksiyonların içinde kullanılabilir. + +--- + +Eğer üçüncü parti kütüphaneler ile beraber birşeyler ile etkileşimde bulunuyorsak(veri tabanı, API, dosya işlemleri, vb.) ve `await` kulanımı desteklenmiyorsa, (birçok veri tabanı kütüphanesi için geçerlidir), o zaman *path operasyon fonksiyonunu* normal bir şekilde, yalnızca `def` kullanarak da tanımlayabiliriz, örneğin: + +```Python hl_lines="2" +@app.get('/') +def results(): + results = some_library() + return results +``` + +--- + +Eğer uygulamanız (bir şekilde) başka bir şeyle iletişim kurması gerekmiyor ama yanıt vermesini beklemeniz gerekiyorsa `async def` kullanabilirsiniz. + +--- + +Sadece bilmiyorsanız, normal `def` kullanın. + +--- + +**Not**: *path operasyon fonksiyonlarında* istediğiniz şekilde `def` yada `async def` kullanabilirsiniz. Sizin için en iyi olan seçeneği kullanabilirsiniz. FastAPI onlarla doğru olanı yapacaktır. + +Yukarıdaki durumlardan herhangi birinde FastAPI yine de asenkron olarak çalışacak ve son derece hızlı olacaktır. + +Ancak yukarıdaki adımları takip ederek bazı performans optimizasyonları yapabiliriz + +## Teknik Detaylar + +Python modern versiyonlarında **`async` ve `await`** sözdizimi ile **"coroutines"** kullanan **"asenkron kod"** desteğine sahiptir. + +Bu ifadeyi aşağıdaki bölümlerde daha da ayrıntılı açıklayalım: + +* **Asenkron kod** +* **`async` ve `await`** +* **Coroutines** + +## Asenkron kod + +Asenkron kod programlama dilinin 💬 bilgisayara / programa 🤖 kodun bir noktasında, *başka bir kodun* bir yerde bitmesini 🤖 beklemesi gerektiğini söylemenin bir yoludur. Bu *başka koda* "slow-file" denir 📝. + +Böylece, bu süreçte bilgisayar "slow-file" 📝 tamamlanırken gidip başka işler yapabilir. + +Sonra bilgisayar / program 🤖 her fırsatı olduğunda o noktada yaptığı tüm işleri 🤖 bitirene kadar geri dönücek. Ve 🤖 yapması gerekeni yaparak, beklediği görevlerden herhangi birinin bitip bitmediğini görecek. + +Ardından, 🤖 bitirmek için ilk görevi alır ("slow-file" 📝) ve onunla ne yapması gerekiyorsa onu devam ettirir. + +Bu "başka bir şey için bekle" normalde, aşağıdakileri beklemek gibi (işlemcinin ve RAM belleğinin hızına kıyasla) nispeten "yavaş" olan I/O işlemlerine atıfta bulunur: + +* istemci tarafından ağ üzerinden veri göndermek +* ağ üzerinden istemciye gönderilen veriler +* sistem tarafından okunacak ve programınıza verilecek bir dosya içeriği +* programınızın diske yazılmak üzere sisteme verdiği dosya içerikleri +* uzak bir API işlemi +* bir veritabanı bitirme işlemi +* sonuçları döndürmek için bir veritabanı sorgusu +* vb. + +Yürütme süresi çoğunlukla I/O işlemleri beklenerek tüketildiğinden bunlara "I/O bağlantılı" işlemler denir. + +Buna "asenkron" denir, çünkü bilgisayar/program yavaş görevle "senkronize" olmak zorunda değildir, görevin tam olarak biteceği anı bekler, hiçbir şey yapmadan, görev sonucunu alabilmek ve çalışmaya devam edebilmek için . + +Bunun yerine, "asenkron" bir sistem olarak, bir kez bittiğinde, bilgisayarın / programın yapması gerekeni bitirmesi için biraz (birkaç mikrosaniye) sırada bekleyebilir ve ardından sonuçları almak için geri gelebilir ve onlarla çalışmaya devam edebilir. + +"Senkron" ("asenkron"un aksine) için genellikle "sıralı" terimini de kullanırlar, çünkü bilgisayar/program, bu adımlar beklemeyi içerse bile, farklı bir göreve geçmeden önce tüm adımları sırayla izler. + + +### Eşzamanlılık (Concurrency) ve Burgerler + + +Yukarıda açıklanan bu **asenkron** kod fikrine bazen **"eşzamanlılık"** da denir. **"Paralellikten"** farklıdır. + +**Eşzamanlılık** ve **paralellik**, "aynı anda az ya da çok olan farklı işler" ile ilgilidir. + +Ancak *eşzamanlılık* ve *paralellik* arasındaki ayrıntılar oldukça farklıdır. + + +Farkı görmek için burgerlerle ilgili aşağıdaki hikayeyi hayal edin: + +### Eşzamanlı Burgerler + + + +Aşkınla beraber 😍 dışarı hamburger yemeye çıktınız 🍔, kasiyer 💁 öndeki insanlardan sipariş alırken siz sıraya girdiniz. + +Sıra sizde ve sen aşkın 😍 ve kendin için 2 çılgın hamburger 🍔 söylüyorsun. + +Ödemeyi yaptın 💸. + +Kasiyer 💁 mutfakdaki aşçıya 👨‍🍳 hamburgerleri 🍔 hazırlaması gerektiğini söyler ve aşçı bunu bilir (o an önceki müşterilerin siparişlerini hazırlıyor olsa bile). + +Kasiyer 💁 size bir sıra numarası verir. + +Beklerken askınla 😍 bir masaya oturur ve uzun bir süre konuşursunuz(Burgerleriniz çok çılgın olduğundan ve hazırlanması biraz zaman alıyor ✨🍔✨). + +Hamburgeri beklerkenki zamanı 🍔, aşkının ne kadar zeki ve tatlı olduğuna hayran kalarak harcayabilirsin ✨😍✨. + +Aşkınla 😍 konuşurken arada sıranın size gelip gelmediğini kontrol ediyorsun. + +Nihayet sıra size geldi. Tezgaha gidip hamburgerleri 🍔kapıp masaya geri dönüyorsun. + +Aşkınla hamburgerlerinizi yiyor 🍔 ve iyi vakit geçiriyorsunuz ✨. + +--- + +Bu hikayedeki bilgisayar / program 🤖 olduğunuzu hayal edin. + +Sırada beklerken boştasın 😴, sıranı beklerken herhangi bir "üretim" yapmıyorsun. Ama bu sıra hızlı çünkü kasiyer sadece siparişleri alıyor (onları hazırlamıyor), burada bir sıknıtı yok. + +Sonra sıra size geldiğinde gerçekten "üretken" işler yapabilirsiniz 🤓, menüyü oku, ne istediğine larar ver, aşkının seçimini al 😍, öde 💸, doğru kartı çıkart, ödemeyi kontrol et, faturayı kontrol et, siparişin doğru olup olmadığını kontrol et, vb. + +Ama hamburgerler 🍔 hazır olmamasına rağmen Kasiyer 💁 ile işiniz "duraklıyor" ⏸, çünkü hamburgerlerin hazır olmasını bekliyoruz 🕙. + +Ama tezgahtan uzaklaşıp sıranız gelene kadarmasanıza dönebilir 🔀 ve dikkatinizi aşkınıza 😍 verebilirsiniz vr bunun üzerine "çalışabilirsiniz" ⏯ 🤓. Artık "üretken" birşey yapıyorsunuz 🤓, sevgilinle 😍 flört eder gibi. + +Kasiyer 💁 "Hamburgerler hazır !" 🍔 dediğinde ve görüntülenen numara sizin numaranız olduğunda hemen koşup hamburgerlerinizi almaya çalışmıyorsunuz. Biliyorsunuzki kimse sizin hamburgerlerinizi 🍔 çalmayacak çünkü sıra sizin. + +Yani Aşkınızın😍 hikayeyi bitirmesini bekliyorsunuz (çalışmayı bitir ⏯ / görev işleniyor.. 🤓), nazikçe gülümseyin ve hamburger yemeye gittiğinizi söyleyin ⏸. + +Ardından tezgaha 🔀, şimdi biten ilk göreve ⏯ gidin, Hamburgerleri 🍔 alın, teşekkür edin ve masaya götürün. sayacın bu adımı tamamlanır ⏹. Bu da yeni bir görev olan "hamburgerleri ye" 🔀 ⏯ görevini başlatırken "hamburgerleri al" ⏹ görevini bitirir. + +### Parallel Hamburgerler + +Şimdi bunların "Eşzamanlı Hamburger" değil, "Paralel Hamburger" olduğunu düşünelim. + +Hamburger 🍔 almak için 😍 aşkınla Paralel fast food'a gidiyorsun. + +You stand in line while several (let's say 8) cashiers that at the same time are cooks 👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳 take the orders from the people in front of you. + +Everyone before you is waiting 🕙 for their burgers 🍔 to be ready before leaving the counter because each of the 8 cashiers goes and prepares the burger right away before getting the next order. + +Then it's finally your turn, you place your order of 2 very fancy burgers 🍔 for your crush 😍 and you. + +You pay 💸. + +The cashier goes to the kitchen 👨‍🍳. + +You wait, standing in front of the counter 🕙, so that no one else takes your burgers 🍔 before you do, as there are no numbers for turns. + +As you and your crush 😍 are busy not letting anyone get in front of you and take your burgers whenever they arrive 🕙, you cannot pay attention to your crush 😞. + +This is "synchronous" work, you are "synchronized" with the cashier/cook 👨‍🍳. You have to wait 🕙 and be there at the exact moment that the cashier/cook 👨‍🍳 finishes the burgers 🍔 and gives them to you, or otherwise, someone else might take them. + +Then your cashier/cook 👨‍🍳 finally comes back with your burgers 🍔, after a long time waiting 🕙 there in front of the counter. + +You take your burgers 🍔 and go to the table with your crush 😍. + +You just eat them, and you are done 🍔 ⏹. + +There was not much talk or flirting as most of the time was spent waiting 🕙 in front of the counter 😞. + +--- + +In this scenario of the parallel burgers, you are a computer / program 🤖 with two processors (you and your crush 😍), both waiting 🕙 and dedicating their attention ⏯ to be "waiting on the counter" 🕙 for a long time. + +The fast food store has 8 processors (cashiers/cooks) 👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳. While the concurrent burgers store might have had only 2 (one cashier and one cook) 💁 👨‍🍳. + +But still, the final experience is not the best 😞. + +--- + +This would be the parallel equivalent story for burgers 🍔. + +For a more "real life" example of this, imagine a bank. + +Up to recently, most of the banks had multiple cashiers 👨‍💼👨‍💼👨‍💼👨‍💼 and a big line 🕙🕙🕙🕙🕙🕙🕙🕙. + +All of the cashiers doing all the work with one client after the other 👨‍💼⏯. + +And you have to wait 🕙 in the line for a long time or you lose your turn. + +You probably wouldn't want to take your crush 😍 with you to do errands at the bank 🏦. + +### Burger Conclusion + +In this scenario of "fast food burgers with your crush", as there is a lot of waiting 🕙, it makes a lot more sense to have a concurrent system ⏸🔀⏯. + +This is the case for most of the web applications. + +Many, many users, but your server is waiting 🕙 for their not-so-good connection to send their requests. + +And then waiting 🕙 again for the responses to come back. + +This "waiting" 🕙 is measured in microseconds, but still, summing it all, it's a lot of waiting in the end. + +That's why it makes a lot of sense to use asynchronous ⏸🔀⏯ code for web APIs. + +Most of the existing popular Python frameworks (including Flask and Django) were created before the new asynchronous features in Python existed. So, the ways they can be deployed support parallel execution and an older form of asynchronous execution that is not as powerful as the new capabilities. + +Even though the main specification for asynchronous web Python (ASGI) was developed at Django, to add support for WebSockets. + +That kind of asynchronicity is what made NodeJS popular (even though NodeJS is not parallel) and that's the strength of Go as a programming language. + +And that's the same level of performance you get with **FastAPI**. + +And as you can have parallelism and asynchronicity at the same time, you get higher performance than most of the tested NodeJS frameworks and on par with Go, which is a compiled language closer to C (all thanks to Starlette). + +### Is concurrency better than parallelism? + +Nope! That's not the moral of the story. + +Concurrency is different than parallelism. And it is better on **specific** scenarios that involve a lot of waiting. Because of that, it generally is a lot better than parallelism for web application development. But not for everything. + +So, to balance that out, imagine the following short story: + +> You have to clean a big, dirty house. + +*Yep, that's the whole story*. + +--- + +There's no waiting 🕙 anywhere, just a lot of work to be done, on multiple places of the house. + +You could have turns as in the burgers example, first the living room, then the kitchen, but as you are not waiting 🕙 for anything, just cleaning and cleaning, the turns wouldn't affect anything. + +It would take the same amount of time to finish with or without turns (concurrency) and you would have done the same amount of work. + +But in this case, if you could bring the 8 ex-cashier/cooks/now-cleaners 👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳, and each one of them (plus you) could take a zone of the house to clean it, you could do all the work in **parallel**, with the extra help, and finish much sooner. + +In this scenario, each one of the cleaners (including you) would be a processor, doing their part of the job. + +And as most of the execution time is taken by actual work (instead of waiting), and the work in a computer is done by a CPU, they call these problems "CPU bound". + +--- + +Common examples of CPU bound operations are things that require complex math processing. + +For example: + +* **Audio** or **image processing**. +* **Computer vision**: an image is composed of millions of pixels, each pixel has 3 values / colors, processing that normally requires computing something on those pixels, all at the same time. +* **Machine Learning**: it normally requires lots of "matrix" and "vector" multiplications. Think of a huge spreadsheet with numbers and multiplying all of them together at the same time. +* **Deep Learning**: this is a sub-field of Machine Learning, so, the same applies. It's just that there is not a single spreadsheet of numbers to multiply, but a huge set of them, and in many cases, you use a special processor to build and / or use those models. + +### Concurrency + Parallelism: Web + Machine Learning + +With **FastAPI** you can take the advantage of concurrency that is very common for web development (the same main attractive of NodeJS). + +But you can also exploit the benefits of parallelism and multiprocessing (having multiple processes running in parallel) for **CPU bound** workloads like those in Machine Learning systems. + +That, plus the simple fact that Python is the main language for **Data Science**, Machine Learning and especially Deep Learning, make FastAPI a very good match for Data Science / Machine Learning web APIs and applications (among many others). + +To see how to achieve this parallelism in production see the section about [Deployment](deployment/index.md){.internal-link target=_blank}. + +## `async` and `await` + +Modern versions of Python have a very intuitive way to define asynchronous code. This makes it look just like normal "sequential" code and do the "awaiting" for you at the right moments. + +When there is an operation that will require waiting before giving the results and has support for these new Python features, you can code it like: + +```Python +burgers = await get_burgers(2) +``` + +The key here is the `await`. It tells Python that it has to wait ⏸ for `get_burgers(2)` to finish doing its thing 🕙 before storing the results in `burgers`. With that, Python will know that it can go and do something else 🔀 ⏯ in the meanwhile (like receiving another request). + +For `await` to work, it has to be inside a function that supports this asynchronicity. To do that, you just declare it with `async def`: + +```Python hl_lines="1" +async def get_burgers(number: int): + # Do some asynchronous stuff to create the burgers + return burgers +``` + +...instead of `def`: + +```Python hl_lines="2" +# This is not asynchronous +def get_sequential_burgers(number: int): + # Do some sequential stuff to create the burgers + return burgers +``` + +With `async def`, Python knows that, inside that function, it has to be aware of `await` expressions, and that it can "pause" ⏸ the execution of that function and go do something else 🔀 before coming back. + +When you want to call an `async def` function, you have to "await" it. So, this won't work: + +```Python +# This won't work, because get_burgers was defined with: async def +burgers = get_burgers(2) +``` + +--- + +So, if you are using a library that tells you that you can call it with `await`, you need to create the *path operation functions* that uses it with `async def`, like in: + +```Python hl_lines="2-3" +@app.get('/burgers') +async def read_burgers(): + burgers = await get_burgers(2) + return burgers +``` + +### More technical details + +You might have noticed that `await` can only be used inside of functions defined with `async def`. + +But at the same time, functions defined with `async def` have to be "awaited". So, functions with `async def` can only be called inside of functions defined with `async def` too. + +So, about the egg and the chicken, how do you call the first `async` function? + +If you are working with **FastAPI** you don't have to worry about that, because that "first" function will be your *path operation function*, and FastAPI will know how to do the right thing. + +But if you want to use `async` / `await` without FastAPI, check the official Python docs. + +### Other forms of asynchronous code + +This style of using `async` and `await` is relatively new in the language. + +But it makes working with asynchronous code a lot easier. + +This same syntax (or almost identical) was also included recently in modern versions of JavaScript (in Browser and NodeJS). + +But before that, handling asynchronous code was quite more complex and difficult. + +In previous versions of Python, you could have used threads or Gevent. But the code is way more complex to understand, debug, and think about. + +In previous versions of NodeJS / Browser JavaScript, you would have used "callbacks". Which leads to callback hell. + +## Coroutines + +**Coroutine** is just the very fancy term for the thing returned by an `async def` function. Python knows that it is something like a function that it can start and that it will end at some point, but that it might be paused ⏸ internally too, whenever there is an `await` inside of it. + +But all this functionality of using asynchronous code with `async` and `await` is many times summarized as using "coroutines". It is comparable to the main key feature of Go, the "Goroutines". + +## Conclusion + +Let's see the same phrase from above: + +> Modern versions of Python have support for **"asynchronous code"** using something called **"coroutines"**, with **`async` and `await`** syntax. + +That should make more sense now. ✨ + +All that is what powers FastAPI (through Starlette) and what makes it have such an impressive performance. + +## Very Technical Details + +!!! warning + You can probably skip this. + + These are very technical details of how **FastAPI** works underneath. + + If you have quite some technical knowledge (co-routines, threads, blocking, etc) and are curious about how FastAPI handles `async def` vs normal `def`, go ahead. + +### Path operation functions + +When you declare a *path operation function* with normal `def` instead of `async def`, it is run in an external threadpool that is then awaited, instead of being called directly (as it would block the server). + +If you are coming from another async framework that does not work in the way described above and you are used to define trivial compute-only *path operation functions* with plain `def` for a tiny performance gain (about 100 nanoseconds), please note that in **FastAPI** the effect would be quite opposite. In these cases, it's better to use `async def` unless your *path operation functions* use code that performs blocking I/O. + +Still, in both situations, chances are that **FastAPI** will [still be faster](/#performance){.internal-link target=_blank} than (or at least comparable to) your previous framework. + +### Dependencies + +The same applies for dependencies. If a dependency is a standard `def` function instead of `async def`, it is run in the external threadpool. + +### Sub-dependencies + +You can have multiple dependencies and sub-dependencies requiring each other (as parameters of the function definitions), some of them might be created with `async def` and some with normal `def`. It would still work, and the ones created with normal `def` would be called on an external thread (from the threadpool) instead of being "awaited". + +### Other utility functions + +Any other utility function that you call directly can be created with normal `def` or `async def` and FastAPI won't affect the way you call it. + +This is in contrast to the functions that FastAPI calls for you: *path operation functions* and dependencies. + +If your utility function is a normal function with `def`, it will be called directly (as you write it in your code), not in a threadpool, if the function is created with `async def` then you should `await` for that function when you call it in your code. + +--- + +Again, these are very technical details that would probably be useful if you came searching for them. + +Otherwise, you should be good with the guidelines from the section above: In a hurry?. diff --git a/docs/tr/mkdocs.yml b/docs/tr/mkdocs.yml index f6ed7f5b9c336..207d6e3511e7b 100644 --- a/docs/tr/mkdocs.yml +++ b/docs/tr/mkdocs.yml @@ -55,6 +55,7 @@ nav: - features.md - fastapi-people.md - python-types.md +- async.md markdown_extensions: - toc: permalink: true From 74b9f3c2c44d5d685d37b2d483b0ee19c2251b2c Mon Sep 17 00:00:00 2001 From: bilalAlpaslan Date: Sun, 24 Jul 2022 17:05:12 +0300 Subject: [PATCH 2/7] turkish translate --- docs/tr/docs/async.md | 213 +++++++++++++++++++++--------------------- 1 file changed, 108 insertions(+), 105 deletions(-) diff --git a/docs/tr/docs/async.md b/docs/tr/docs/async.md index af3b33cff371e..1e72d594487c2 100644 --- a/docs/tr/docs/async.md +++ b/docs/tr/docs/async.md @@ -151,164 +151,166 @@ Ardından tezgaha 🔀, şimdi biten ilk göreve ⏯ gidin, Hamburgerleri 🍔 a Hamburger 🍔 almak için 😍 aşkınla Paralel fast food'a gidiyorsun. -You stand in line while several (let's say 8) cashiers that at the same time are cooks 👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳 take the orders from the people in front of you. +Birden fazla kasiyer varken (varsayalım 8) sıraya girdiniz👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳 ve sıranız gelene kadar bekliyorsunuz. -Everyone before you is waiting 🕙 for their burgers 🍔 to be ready before leaving the counter because each of the 8 cashiers goes and prepares the burger right away before getting the next order. +Sizden önceki herkez ayrılmadan önce hamburgerlerinin 🍔 hazır olmasını bekliyor 🕙. Çünkü kasiyerlerin her biri bir hamburger hazırlanmadan önce bir sonraki siparişe geçmiiyor. -Then it's finally your turn, you place your order of 2 very fancy burgers 🍔 for your crush 😍 and you. +Sonunda senin sıran, aşkın 😍 ve kendin için 2 hamburger 🍔 siparişi verdiniz. -You pay 💸. +Ödemeyi yaptınız 💸. -The cashier goes to the kitchen 👨‍🍳. +Kasiyer mutfağa gider 👨‍🍳. -You wait, standing in front of the counter 🕙, so that no one else takes your burgers 🍔 before you do, as there are no numbers for turns. +Sırada bekliyorsunuz 🕙, kimse sizin burgerinizi 🍔 almaya çalışmıyor çünkü sıra sizin. -As you and your crush 😍 are busy not letting anyone get in front of you and take your burgers whenever they arrive 🕙, you cannot pay attention to your crush 😞. +Sen ve aşkın 😍 sıranızı korumak ve hamburgerleri almakla o kadar meşgulsünüz ki birbirinize vakit 🕙 ayıramıyorsunuz 😞. -This is "synchronous" work, you are "synchronized" with the cashier/cook 👨‍🍳. You have to wait 🕙 and be there at the exact moment that the cashier/cook 👨‍🍳 finishes the burgers 🍔 and gives them to you, or otherwise, someone else might take them. +İşte bu "senkron" çalışmadır. Kasiyer/aşçı 👨‍🍳ile senkron hareket ediyorsunuz. Bu yüzden beklemek 🕙 ve kasiyer/aşçı burgeri 🍔bitirip size getirdiğinde orda olmak zorundasınız yoksa başka biri alabilir. -Then your cashier/cook 👨‍🍳 finally comes back with your burgers 🍔, after a long time waiting 🕙 there in front of the counter. +Sonra kasiyeri/aşçı 👨‍🍳 nihayet hamburgerlerinizle 🍔, uzun bir süre sonra 🕙 tezgaha geri geliyor. -You take your burgers 🍔 and go to the table with your crush 😍. +Burgerlerinizi 🍔 al ve aşkınla masanıza doğru ilerle 😍. -You just eat them, and you are done 🍔 ⏹. +Sadece burgerini yiyorsun 🍔 ve bitti ⏹. -There was not much talk or flirting as most of the time was spent waiting 🕙 in front of the counter 😞. +Bekleyerek çok fazla zaman geçtiğinden 🕙 konuşmaya çok fazla vakit kalmadı 😞. --- -In this scenario of the parallel burgers, you are a computer / program 🤖 with two processors (you and your crush 😍), both waiting 🕙 and dedicating their attention ⏯ to be "waiting on the counter" 🕙 for a long time. +Paralel burger senaryosunda ise, siz iki işlemcili birer robotsunuz 🤖 (sen ve sevgilin 😍), Beklıyorsunuz 🕙 hem konuşarak güzel vakit geçirirken ⏯ hem de sıranızı bekliyorsunuz 🕙. -The fast food store has 8 processors (cashiers/cooks) 👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳. While the concurrent burgers store might have had only 2 (one cashier and one cook) 💁 👨‍🍳. +Mağazada ise 8 işlemci bulunuyor (Kasiyer/aşçı) 👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳. Eşzamanlı burgerde yalnızca 2 kişi olabiliyordu (bir kasiyer ve bir aşçı) 💁 👨‍🍳. -But still, the final experience is not the best 😞. +Ama yine de bu en iyisi değil 😞. --- -This would be the parallel equivalent story for burgers 🍔. +Bu hikaye burgerler 🍔 için paralel. -For a more "real life" example of this, imagine a bank. +Bir gerçek hayat örneği verelim. Bir banka hayal edin. -Up to recently, most of the banks had multiple cashiers 👨‍💼👨‍💼👨‍💼👨‍💼 and a big line 🕙🕙🕙🕙🕙🕙🕙🕙. +Bankaların çoğunda birkaç kasiyer 👨‍💼👨‍💼👨‍💼👨‍💼 ve uzun bir sıra var 🕙🕙🕙🕙🕙🕙🕙🕙. -All of the cashiers doing all the work with one client after the other 👨‍💼⏯. +Tüm işi sırayla bir müşteri ile yapan tüm kasiyerler 👨‍💼⏯. -And you have to wait 🕙 in the line for a long time or you lose your turn. +Ve uzun süre kuyrukta beklemek 🕙 zorundasın yoksa sıranı kaybedersin. -You probably wouldn't want to take your crush 😍 with you to do errands at the bank 🏦. +Muhtemelen ayak işlerı yaparken sevgilini 😍 bankaya 🏦 getirmezsin. -### Burger Conclusion +### Burger Sonucu -In this scenario of "fast food burgers with your crush", as there is a lot of waiting 🕙, it makes a lot more sense to have a concurrent system ⏸🔀⏯. +Bu "aşkınla fast food burgerleri" senaryosunda, çok fazla bekleme olduğu için 🕙, eşzamanlı bir sisteme sahip olmak çok daha mantıklı ⏸🔀⏯. -This is the case for most of the web applications. +Web uygulamalarının çoğu için durum böyledir. -Many, many users, but your server is waiting 🕙 for their not-so-good connection to send their requests. +Pek çok kullanıcı var, ama sunucunuz pek de iyi olmayan bir bağlantı ile istek atmalarını bekliyor. -And then waiting 🕙 again for the responses to come back. +Ve sonra yanıtların geri gelmesi için tekrar 🕙 bekliyor -This "waiting" 🕙 is measured in microseconds, but still, summing it all, it's a lot of waiting in the end. +Bu "bekleme" 🕙 mikrosaniye cinsinden ölçülür, yine de, hepsini toplarsak çok fazla bekleme var. -That's why it makes a lot of sense to use asynchronous ⏸🔀⏯ code for web APIs. +Bu nedenle, web API'leri için asenkron ⏸🔀⏯ kod kullanmak çok daha mantıklı. -Most of the existing popular Python frameworks (including Flask and Django) were created before the new asynchronous features in Python existed. So, the ways they can be deployed support parallel execution and an older form of asynchronous execution that is not as powerful as the new capabilities. +Mevcut popüler Python frameworklerinin çoğu (Flask ve Django gibi), Python'daki yeni asenkron özellikler mevcut olmadan önce yazıldı. Bu nedenle, dağıtılma biçimleri paralel yürütmeyi ve yenisi kadar güçlü olmayan eski bir eşzamansız yürütme biçimini destekler. -Even though the main specification for asynchronous web Python (ASGI) was developed at Django, to add support for WebSockets. +Asenkron web (ASGI) özelliği, WebSockets için destek eklemek için Django'ya eklenmiş olsa da. -That kind of asynchronicity is what made NodeJS popular (even though NodeJS is not parallel) and that's the strength of Go as a programming language. +Asenkron çalışabilme NodeJS in popüler olmasının sebebi (paralel olamasa bile) ve Go dilini güçlü yapan özelliktir. -And that's the same level of performance you get with **FastAPI**. +Ve bu **FastAPI** ile elde ettiğiniz performans düzeyiyle aynıdır. -And as you can have parallelism and asynchronicity at the same time, you get higher performance than most of the tested NodeJS frameworks and on par with Go, which is a compiled language closer to C (all thanks to Starlette). +Aynı anda paralellik ve asenkronluğa sahip olabildiğiniz için, test edilen NodeJS çerçevelerinin çoğundan daha yüksek performans elde edersiniz ve C'ye daha yakın derlenmiş bir dil olan Go ile eşit bir performans elde edersiniz (bütün teşekkürler Starlette'e ). -### Is concurrency better than parallelism? +### Eşzamanlılık paralellikten daha mı iyi? -Nope! That's not the moral of the story. +Hayır! Hikayenin ahlakı bu değil. -Concurrency is different than parallelism. And it is better on **specific** scenarios that involve a lot of waiting. Because of that, it generally is a lot better than parallelism for web application development. But not for everything. +Eşzamanlılık paralellikten farklıdır. Ve çok fazla bekleme içeren **belirli** senaryolarda daha iyidir. Bu nedenle, genellikle web uygulamaları için paralellikten çok daha iyidir. Ama her şey için değil. -So, to balance that out, imagine the following short story: +Yanı, bunu aklınızda oturtmak için aşağıdaki kısa hikayeyi hayal edin: -> You have to clean a big, dirty house. +> Büyük, kirli bir evi temizlemelisin. -*Yep, that's the whole story*. +*Evet, tüm hikaye bu*. --- -There's no waiting 🕙 anywhere, just a lot of work to be done, on multiple places of the house. +Beklemek yok 🕙. Hiçbir yerde. Sadece evin birden fazla yerinde yapılacak fazlasıyla iş var. You could have turns as in the burgers example, first the living room, then the kitchen, but as you are not waiting 🕙 for anything, just cleaning and cleaning, the turns wouldn't affect anything. +Hamburger örneğindeki gibi dönüşleriniz olabilir, önce oturma odası, sonra mutfak, ama hiçbir şey için 🕙 beklemediğinizden, sadece temizlik, temizlik ve temizlik, dönüşler hiçbir şeyi etkilemez. -It would take the same amount of time to finish with or without turns (concurrency) and you would have done the same amount of work. +Sıralı veya sırasız (eşzamanlılık) bitirmek aynı zaman alır ve aynı miktarda işi yaparsınız. -But in this case, if you could bring the 8 ex-cashier/cooks/now-cleaners 👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳, and each one of them (plus you) could take a zone of the house to clean it, you could do all the work in **parallel**, with the extra help, and finish much sooner. +Ama bu durumda, 8 eski kasiyer/aşçı - yeni temizlikçiyi getirebilseydiniz 👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳👩‍🍳👨‍🍳 ve her birini (artı siz) evin bir bölgesini temizlemek için görevlendirseydiniz, ekstra yardımla tüm işleri **paralel** olarak yapabilir ve çok daha erken bitirebilirdiniz. -In this scenario, each one of the cleaners (including you) would be a processor, doing their part of the job. +Bu senaryoda, temizlikçilerin her biri (siz dahil) birer işlemci olacak ve üzerine düşeni yapacaktır. -And as most of the execution time is taken by actual work (instead of waiting), and the work in a computer is done by a CPU, they call these problems "CPU bound". +Yürütme süresinin çoğu (beklemek yerine) iş yapıldığından ve bilgisayardaki iş bir CPU tarafından yapıldığından, bu sorunlara "CPU bound" diyorlar". --- -Common examples of CPU bound operations are things that require complex math processing. +CPU'ya bağlı işlemlerin yaygın örnekleri, karmaşık matematik işlemleri gerektiren işlerdir. -For example: +Örneğin: -* **Audio** or **image processing**. -* **Computer vision**: an image is composed of millions of pixels, each pixel has 3 values / colors, processing that normally requires computing something on those pixels, all at the same time. -* **Machine Learning**: it normally requires lots of "matrix" and "vector" multiplications. Think of a huge spreadsheet with numbers and multiplying all of them together at the same time. -* **Deep Learning**: this is a sub-field of Machine Learning, so, the same applies. It's just that there is not a single spreadsheet of numbers to multiply, but a huge set of them, and in many cases, you use a special processor to build and / or use those models. +* **Ses** veya **görüntü işleme**. +* **Bilgisayar görüsü**: bir görüntü milyonlarca pikselden oluşur, her pikselin 3 değeri / rengi vardır, bu pikseller üzerinde aynı anda bir şeyler hesaplamayı gerektiren işleme. +* **Makine Öğrenimi**: Çok sayıda "matris" ve "vektör" çarpımı gerektirir. Sayıları olan ve hepsini aynı anda çarpan büyük bir elektronik tablo düşünün. +* **Derin Öğrenme**: Bu, Makine Öğreniminin bir alt alanıdır, dolayısıyla aynısı geçerlidir. Sadece çarpılacak tek bir sayı tablosu değil, büyük bir sayı kümesi vardır ve çoğu durumda bu modelleri oluşturmak ve/veya kullanmak için özel işlemciler kullanırsınız. -### Concurrency + Parallelism: Web + Machine Learning +### Eşzamanlılık + Paralellik: Web + Makine Öğrenimi -With **FastAPI** you can take the advantage of concurrency that is very common for web development (the same main attractive of NodeJS). +**FastAPI** ile web geliştirme için çok yaygın olan eşzamanlılıktan yararlanabilirsiniz (NodeJS'in aynı çekiciliği). -But you can also exploit the benefits of parallelism and multiprocessing (having multiple processes running in parallel) for **CPU bound** workloads like those in Machine Learning systems. +Ancak, Makine Öğrenimi sistemlerindekile gibi **CPU'ya bağlı** iş yükleri için paralellik ve çoklu işlemenin (birden çok işlemin paralel olarak çalışması) avantajlarından da yararlanabilirsiniz. That, plus the simple fact that Python is the main language for **Data Science**, Machine Learning and especially Deep Learning, make FastAPI a very good match for Data Science / Machine Learning web APIs and applications (among many others). +Buna ek olarak Python'un **Veri Bilimi**, Makine Öğrenimi ve özellikle Derin Öğrenme için ana dil olduğu gerçeği, FastAPI'yi Veri Bilimi / Makine Öğrenimi web API'leri ve uygulamaları için çok iyi bir seçenek haline getirir. -To see how to achieve this parallelism in production see the section about [Deployment](deployment/index.md){.internal-link target=_blank}. +Production'da nasıl oldugunu görmek için şu bölüme bakın [Deployment](deployment/index.md){.internal-link target=_blank}. -## `async` and `await` +## `async` ve `await` -Modern versions of Python have a very intuitive way to define asynchronous code. This makes it look just like normal "sequential" code and do the "awaiting" for you at the right moments. +Python'un modern sürümleri, asenkron kodu tanımlamanın çok sezgisel bir yoluna sahiptir. Bu, normal "sequentıal" (sıralı) kod gibi görünmesini ve doğru anlarda sizin için "awaıt" ile bekleme yapmasını sağlar. -When there is an operation that will require waiting before giving the results and has support for these new Python features, you can code it like: +Sonuçları vermeden önce beklemeyi gerektirecek ve yeni Python özelliklerini destekleyen bir işlem olduğunda aşağıdaki gibi kodlayabilirsiniz: ```Python burgers = await get_burgers(2) ``` -The key here is the `await`. It tells Python that it has to wait ⏸ for `get_burgers(2)` to finish doing its thing 🕙 before storing the results in `burgers`. With that, Python will know that it can go and do something else 🔀 ⏯ in the meanwhile (like receiving another request). +Buradaki `await` anahtari Python'a, sonuçları `burgers` degiskenine atamadan önce `get_burgers(2)` kodunun işini bitirmesini 🕙 beklemesi gerektiğini söyler. Bununla Python, bu ara zamanda başka bir şey 🔀 ⏯ yapabileceğini bilecektir (başka bir istek almak gibi). -For `await` to work, it has to be inside a function that supports this asynchronicity. To do that, you just declare it with `async def`: + `await`kodunun çalışması için, eşzamansızlığı destekleyen bir fonksiyonun içinde olması gerekir. Bunu da yapmak için fonksiyonu `async def` ile tanımlamamız yeterlidir: ```Python hl_lines="1" async def get_burgers(number: int): - # Do some asynchronous stuff to create the burgers + # burgerleri oluşturmak için asenkron birkaç iş return burgers ``` ...instead of `def`: ```Python hl_lines="2" -# This is not asynchronous +# bu kod asenkron değil def get_sequential_burgers(number: int): - # Do some sequential stuff to create the burgers + # burgerleri oluşturmak için senkron bırkaç iş return burgers ``` -With `async def`, Python knows that, inside that function, it has to be aware of `await` expressions, and that it can "pause" ⏸ the execution of that function and go do something else 🔀 before coming back. +`async def` ile Python, bu fonksıyonun içinde, `await` ifadelerinin farkında olması gerektiğini ve çalışma zamanı gelmeden önce bu işlevin yürütülmesini "duraklatabileceğini" ve başka bir şey yapabileceğini 🔀 bilir. -When you want to call an `async def` function, you have to "await" it. So, this won't work: +`async def` fonksiyonunu çağırmak istediğinizde, onu "awaıt" ıle kullanmanız gerekir. Yani, bu işe yaramaz: ```Python -# This won't work, because get_burgers was defined with: async def +# Bu işe yaramaz, çünkü get_burgers, şu şekilde tanımlandı: async def burgers = get_burgers(2) ``` --- -So, if you are using a library that tells you that you can call it with `await`, you need to create the *path operation functions* that uses it with `async def`, like in: +Bu nedenle, size onu `await` ile çağırabileceğinizi söyleyen bir kitaplık kullanıyorsanız, onu `async def` ile tanımlanan *path fonksiyonu* içerisinde kullanmanız gerekir, örneğin: ```Python hl_lines="2-3" @app.get('/burgers') @@ -317,83 +319,84 @@ async def read_burgers(): return burgers ``` -### More technical details +### Daha fazla teknik detay -You might have noticed that `await` can only be used inside of functions defined with `async def`. +`await` in yalnızca `async def` ile tanımlanan fonksıyonların içinde kullanılabileceğini fark etmişsinizdir. -But at the same time, functions defined with `async def` have to be "awaited". So, functions with `async def` can only be called inside of functions defined with `async def` too. +Ama aynı zamanda, `async def` ile tanımlanan fonksiyonların "await" ile beklenmesi gerekir. Bu nedenle, "`async def` içeren fonksiyonlar yalnızca "`async def` ile tanımlanan fonksiyonların içinde çağrılabilir. -So, about the egg and the chicken, how do you call the first `async` function? -If you are working with **FastAPI** you don't have to worry about that, because that "first" function will be your *path operation function*, and FastAPI will know how to do the right thing. +Yani yumurta mı tavukdan, tavuk mu yumurtadan gibi ilk `async` fonksiyonu nasıl çağırılır? -But if you want to use `async` / `await` without FastAPI, check the official Python docs. +**FastAPI** ile çalışıyorsanız bunun için endişelenmenize gerek yok, çünkü bu "ilk" fonksiyon sizin *path fonksiyonunuz* olacak ve FastAPI doğru olanı nasıl yapacağını bilecek. -### Other forms of asynchronous code +Ancak FastAPI olmadan `async` / `await` kullanmak istiyorsanız, resmi Python belgelerini kontrol edin. -This style of using `async` and `await` is relatively new in the language. +### Asenkron kodun diğer biçimleri -But it makes working with asynchronous code a lot easier. +Bu `async` ve `await` kullanimi oldukça yenidir. -This same syntax (or almost identical) was also included recently in modern versions of JavaScript (in Browser and NodeJS). +Ancak asenkron kodla çalışmayı çok daha kolay hale getirir. -But before that, handling asynchronous code was quite more complex and difficult. +Aynı sözdizimi (hemen hemen aynı) son zamanlarda JavaScript'in modern sürümlerine de dahil edildi (Tarayıcı ve NodeJS'de). -In previous versions of Python, you could have used threads or Gevent. But the code is way more complex to understand, debug, and think about. +Ancak bundan önce, asenkron kodu işlemek oldukça karmaşık ve zordu. -In previous versions of NodeJS / Browser JavaScript, you would have used "callbacks". Which leads to callback hell. +Python'un önceki sürümlerinde, threadlerı veya Gevent kullanıyor olabilirdin. Ancak kodu anlamak, hata ayıklamak ve düşünmek çok daha karmaşık olurdu. -## Coroutines +NodeJS / Browser JavaScript'in önceki sürümlerinde, "callback" kullanırdınız. Bu da callbacks cehennemine yol açar. -**Coroutine** is just the very fancy term for the thing returned by an `async def` function. Python knows that it is something like a function that it can start and that it will end at some point, but that it might be paused ⏸ internally too, whenever there is an `await` inside of it. +## Coroutine'ler -But all this functionality of using asynchronous code with `async` and `await` is many times summarized as using "coroutines". It is comparable to the main key feature of Go, the "Goroutines". +**Coroutine**, bir `async def` fonksiyonu tarafından döndürülen değer için çok süslü bir terimdir. Python bunun bir fonksiyon gibi bir noktada başlayıp biteceğini bilir, ancak içinde bir `await` olduğunda dahili olarak da duraklatılabilir ⏸. -## Conclusion +Ancak, `async` ve `await` ile asenkron kod kullanmanın tüm bu işlevselliği, çoğu zaman "Coroutine" kullanmak olarak adlandırılır. Go'nun ana özelliği olan "Goroutines" ile karşılaştırılabilir. -Let's see the same phrase from above: +## Sonuç -> Modern versions of Python have support for **"asynchronous code"** using something called **"coroutines"**, with **`async` and `await`** syntax. +Aynı ifadeyi yukarıdan görelim: -That should make more sense now. ✨ +> Python'ın modern sürümleri, **"async" ve "await"** sözdizimi ile birlikte **"coroutines"** adlı bir özelliği kullanan **"asenkron kod"** desteğine sahiptir. -All that is what powers FastAPI (through Starlette) and what makes it have such an impressive performance. +Şimdi daha mantıklı gelmeli. ✨ -## Very Technical Details +FastAPI'ye (Starlette aracılığıyla) güç veren ve bu kadar etkileyici bir performansa sahip olmasını sağlayan şey budur. + +## Çok Teknik Detaylar !!! warning - You can probably skip this. + Muhtemelen burayı atlayabilirsiniz. - These are very technical details of how **FastAPI** works underneath. + Bunlar, **FastAPI**'nin altta nasıl çalıştığına dair çok teknik ayrıntılardır. - If you have quite some technical knowledge (co-routines, threads, blocking, etc) and are curious about how FastAPI handles `async def` vs normal `def`, go ahead. + Biraz teknik bilginiz varsa (co-routines, threads, blocking, vb)ve FastAPI'nin "async def" ile normal "def" arasındaki farkı nasıl işlediğini merak ediyorsanız, devam edin. -### Path operation functions +### Path fonksiyonu -When you declare a *path operation function* with normal `def` instead of `async def`, it is run in an external threadpool that is then awaited, instead of being called directly (as it would block the server). +"async def" yerine normal "def" ile bir *yol işlem işlevi* bildirdiğinizde, doğrudan çağrılmak yerine (sunucuyu bloke edeceğinden) daha sonra beklenen harici bir iş parçacığı havuzunda çalıştırılır. -If you are coming from another async framework that does not work in the way described above and you are used to define trivial compute-only *path operation functions* with plain `def` for a tiny performance gain (about 100 nanoseconds), please note that in **FastAPI** the effect would be quite opposite. In these cases, it's better to use `async def` unless your *path operation functions* use code that performs blocking I/O. +Yukarıda açıklanan şekilde çalışmayan başka bir asenkron framework'den geliyorsanız ve küçük bir performans kazancı (yaklaşık 100 nanosaniye) için "def" ile *path fonksiyonu* tanımlamaya alışkınsanız, **FastAPI**'de tam tersi olacağını unutmayın. Bu durumlarda, *path fonksiyonu* G/Ç engelleyen durum oluşturmadıkça "async def" kullanmak daha iyidir. -Still, in both situations, chances are that **FastAPI** will [still be faster](/#performance){.internal-link target=_blank} than (or at least comparable to) your previous framework. +Yine de, her iki durumda da, **FastAPI**'nin önceki frameworkden [hala daha hızlı](/#performance){.internal-link target=_blank} (veya en azından karşılaştırılabilir) olma olasılığı vardır. -### Dependencies +### Bagımlılıklar -The same applies for dependencies. If a dependency is a standard `def` function instead of `async def`, it is run in the external threadpool. +Aynısı bağımlılıklar için de geçerlidir. Bir bağımlılık, "async def" yerine standart bir "def" işleviyse, harici iş parçacığı havuzunda çalıştırılır. -### Sub-dependencies +### Alt-bağımlıklar -You can have multiple dependencies and sub-dependencies requiring each other (as parameters of the function definitions), some of them might be created with `async def` and some with normal `def`. It would still work, and the ones created with normal `def` would be called on an external thread (from the threadpool) instead of being "awaited". +Birbirini gerektiren (fonksiyonlarin parametreleri olarak) birden fazla bağımlılık ve alt bağımlılıklarınız olabilir, bazıları 'async def' ve bazıları normal 'def' ile oluşturulabilir. Yine de normal 'def' ile oluşturulanlar, "await" kulanilmadan harici bir iş parçacığında (iş parçacığı havuzundan) çağrılır. -### Other utility functions +### Diğer yardımcı fonksiyonlar -Any other utility function that you call directly can be created with normal `def` or `async def` and FastAPI won't affect the way you call it. +Doğrudan çağırdığınız diğer herhangi bir yardımcı fonksiyonu, normal "def" veya "async def" ile tanimlayabilirsiniz. FastAPI onu çağırma şeklinizi etkilemez. -This is in contrast to the functions that FastAPI calls for you: *path operation functions* and dependencies. +Bu, FastAPI'nin sizin için çağırdığı fonksiyonlarin tam tersidir: *path fonksiyonu* ve bağımlılıklar. -If your utility function is a normal function with `def`, it will be called directly (as you write it in your code), not in a threadpool, if the function is created with `async def` then you should `await` for that function when you call it in your code. +Yardımcı program fonksiyonunuz 'def' ile normal bir işlevse, bir iş parçacığı havuzunda değil doğrudan (kodunuzda yazdığınız gibi) çağrılır, işlev 'async def' ile oluşturulmuşsa çağırıldığı yerde 'await' ile beklemelisiniz. --- -Again, these are very technical details that would probably be useful if you came searching for them. +Yeniden, bunlar, onları aramaya geldiğinizde muhtemelen işinize yarayacak çok teknik ayrıntılardır. -Otherwise, you should be good with the guidelines from the section above: In a hurry?. +Aksi takdirde, yukarıdaki bölümdeki yönergeleri iyi bilmelisiniz: Aceleniz mi var?. From 0d74123b3555c4e67e33f3f2e45a5c5ecc4586ca Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 24 Jul 2022 14:08:12 +0000 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20for?= =?UTF-8?q?mat=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tr/docs/async.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/tr/docs/async.md b/docs/tr/docs/async.md index 1e72d594487c2..5695e95251d55 100644 --- a/docs/tr/docs/async.md +++ b/docs/tr/docs/async.md @@ -71,7 +71,7 @@ Sonra bilgisayar / program 🤖 her fırsatı olduğunda o noktada yaptığı t Ardından, 🤖 bitirmek için ilk görevi alır ("slow-file" 📝) ve onunla ne yapması gerekiyorsa onu devam ettirir. -Bu "başka bir şey için bekle" normalde, aşağıdakileri beklemek gibi (işlemcinin ve RAM belleğinin hızına kıyasla) nispeten "yavaş" olan I/O işlemlerine atıfta bulunur: +Bu "başka bir şey için bekle" normalde, aşağıdakileri beklemek gibi (işlemcinin ve RAM belleğinin hızına kıyasla) nispeten "yavaş" olan I/O işlemlerine atıfta bulunur: * istemci tarafından ağ üzerinden veri göndermek * ağ üzerinden istemciye gönderilen veriler @@ -215,7 +215,7 @@ Mevcut popüler Python frameworklerinin çoğu (Flask ve Django gibi), Python'da Asenkron web (ASGI) özelliği, WebSockets için destek eklemek için Django'ya eklenmiş olsa da. -Asenkron çalışabilme NodeJS in popüler olmasının sebebi (paralel olamasa bile) ve Go dilini güçlü yapan özelliktir. +Asenkron çalışabilme NodeJS in popüler olmasının sebebi (paralel olamasa bile) ve Go dilini güçlü yapan özelliktir. Ve bu **FastAPI** ile elde ettiğiniz performans düzeyiyle aynıdır. @@ -246,7 +246,7 @@ Ama bu durumda, 8 eski kasiyer/aşçı - yeni temizlikçiyi getirebilseydiniz Bu senaryoda, temizlikçilerin her biri (siz dahil) birer işlemci olacak ve üzerine düşeni yapacaktır. -Yürütme süresinin çoğu (beklemek yerine) iş yapıldığından ve bilgisayardaki iş bir CPU tarafından yapıldığından, bu sorunlara "CPU bound" diyorlar". +Yürütme süresinin çoğu (beklemek yerine) iş yapıldığından ve bilgisayardaki iş bir CPU tarafından yapıldığından, bu sorunlara "CPU bound" diyorlar". --- From 486cd3aaf13f1340c413822ee938a1e3ae8f50dd Mon Sep 17 00:00:00 2001 From: bilal alpaslan <47563997+BilalAlpaslan@users.noreply.github.com> Date: Thu, 10 Nov 2022 18:39:18 +0300 Subject: [PATCH 4/7] Apply suggestions from code review Co-authored-by: Hakan Celik --- docs/tr/docs/async.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/tr/docs/async.md b/docs/tr/docs/async.md index 5695e95251d55..606e0f251070a 100644 --- a/docs/tr/docs/async.md +++ b/docs/tr/docs/async.md @@ -1,6 +1,6 @@ # Eşzamanlılık ve async / await -*path operasyon fonksiyonu* için `async def`sözyazımı, asenkron kod, eşzamanlılık ve paralellik hakkında bazı bilgiler. +*path operasyon fonksiyonu* için `async def `sözdizimi, asenkron kod, eşzamanlılık ve paralellik hakkında bazı ayrıntılar. ## Aceleniz mi var? @@ -26,7 +26,7 @@ async def read_results(): --- -Eğer üçüncü parti kütüphaneler ile beraber birşeyler ile etkileşimde bulunuyorsak(veri tabanı, API, dosya işlemleri, vb.) ve `await` kulanımı desteklenmiyorsa, (birçok veri tabanı kütüphanesi için geçerlidir), o zaman *path operasyon fonksiyonunu* normal bir şekilde, yalnızca `def` kullanarak da tanımlayabiliriz, örneğin: +Eğer üçüncü parti kütüphaneler ile beraber birşeyler ile etkileşimde bulunuyorsak (veri tabanı, API, dosya işlemleri, vb.) ve `await` kulanımı desteklenmiyorsa, (birçok veri tabanı kütüphanesi için geçerlidir), o zaman *path operasyon fonksiyonunuzu* normal bir şekilde, yalnızca `def` kullanarak tanımlayın, örneğin: ```Python hl_lines="2" @app.get('/') @@ -45,9 +45,9 @@ Sadece bilmiyorsanız, normal `def` kullanın. --- -**Not**: *path operasyon fonksiyonlarında* istediğiniz şekilde `def` yada `async def` kullanabilirsiniz. Sizin için en iyi olan seçeneği kullanabilirsiniz. FastAPI onlarla doğru olanı yapacaktır. +**Not**: *path operasyon fonksiyonlarınızda* `def` ve `async def`'i ihtiyacınız olduğu kadar karıştırabilir ve her birini sizin için en iyi seçeneği kullanarak tanımlayabilirsiniz. FastAPI onlarla doğru olanı yapacaktır. -Yukarıdaki durumlardan herhangi birinde FastAPI yine de asenkron olarak çalışacak ve son derece hızlı olacaktır. +Her neyse, Yukarıdaki durumlardan herhangi birinde FastAPI yine de asenkron olarak çalışacak ve son derece hızlı olacaktır. Ancak yukarıdaki adımları takip ederek bazı performans optimizasyonları yapabiliriz From 52f734348d4bce5a6076e63656f7e1679855ca7d Mon Sep 17 00:00:00 2001 From: bilalAlpaslan Date: Fri, 2 Jun 2023 15:16:04 +0300 Subject: [PATCH 5/7] Update async.md --- docs/tr/docs/async.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/tr/docs/async.md b/docs/tr/docs/async.md index 606e0f251070a..5506cc62a09e7 100644 --- a/docs/tr/docs/async.md +++ b/docs/tr/docs/async.md @@ -1,4 +1,4 @@ -# Eşzamanlılık ve async / await +# Concurrency ve async / await *path operasyon fonksiyonu* için `async def `sözdizimi, asenkron kod, eşzamanlılık ve paralellik hakkında bazı ayrıntılar. @@ -6,13 +6,13 @@ TL;DR: -Eğer onları `await` ile çağırmanızı söyleyen üçüncü taraf bir kütüphane kullanıyorsanız, örneğin: +Eğer `await` ile çağrılması gerektiğini belirten üçüncü taraf kütüphaneleri kullanıyorsanız, örneğin: ```Python results = await some_library() ``` -O zaman *path operasyon fonksiyonunu* `async def` ile tanımlayın: +O zaman *path operasyon fonksiyonunu* `async def` ile tanımlayın örneğin: ```Python hl_lines="2" @app.get('/') @@ -22,11 +22,11 @@ async def read_results(): ``` !!! not - `await` yalnızca `async def` ile tanımlanan fonksiyonların içinde kullanılabilir. + Sadece `async def` ile tanımlanan fonksiyonlar içinde `await` kullanabilirsiniz. --- -Eğer üçüncü parti kütüphaneler ile beraber birşeyler ile etkileşimde bulunuyorsak (veri tabanı, API, dosya işlemleri, vb.) ve `await` kulanımı desteklenmiyorsa, (birçok veri tabanı kütüphanesi için geçerlidir), o zaman *path operasyon fonksiyonunuzu* normal bir şekilde, yalnızca `def` kullanarak tanımlayın, örneğin: +Eğer bir veritabanı, bir API, dosya sistemi vb. ile iletişim kuran bir üçüncü taraf bir kütüphane kullanıyorsanız ve `await` kullanımını desteklemiyorsa, (bu şu anda çoğu veritabanı kütüphanesi için geçerli bir durumdur), o zaman *path operasyon fonksiyonunuzu* `def` kullanarak normal bir şekilde tanımlayın, örneğin: ```Python hl_lines="2" @app.get('/') @@ -37,7 +37,7 @@ def results(): --- -Eğer uygulamanız (bir şekilde) başka bir şeyle iletişim kurması gerekmiyor ama yanıt vermesini beklemeniz gerekiyorsa `async def` kullanabilirsiniz. +Eğer uygulamanız (bir şekilde) başka bir şeyle iletişim kurmak ve onun cevap vermesini beklemek zorunda değilse, `async def` kullanın. --- @@ -45,11 +45,11 @@ Sadece bilmiyorsanız, normal `def` kullanın. --- -**Not**: *path operasyon fonksiyonlarınızda* `def` ve `async def`'i ihtiyacınız olduğu kadar karıştırabilir ve her birini sizin için en iyi seçeneği kullanarak tanımlayabilirsiniz. FastAPI onlarla doğru olanı yapacaktır. +**Not**: *path operasyon fonksiyonlarınızda* `def` ve `async def`'i ihtiyaç duyduğunuz gibi karıştırabilir ve her birini sizin için en iyi seçeneği kullanarak tanımlayabilirsiniz. FastAPI onlarla doğru olanı yapacaktır. -Her neyse, Yukarıdaki durumlardan herhangi birinde FastAPI yine de asenkron olarak çalışacak ve son derece hızlı olacaktır. +Her neyse, yukarıdaki durumlardan herhangi birinde, FastAPI yine de asenkron olarak çalışacak ve son derece hızlı olacaktır. -Ancak yukarıdaki adımları takip ederek bazı performans optimizasyonları yapabiliriz +Ancak yukarıdaki adımları takip ederek, bazı performans optimizasyonları yapılabilecektir. ## Teknik Detaylar From 3722aa198c36cd385c8c5bcf292362d6c3756f8a Mon Sep 17 00:00:00 2001 From: bilal alpaslan <47563997+BilalAlpaslan@users.noreply.github.com> Date: Fri, 2 Jun 2023 15:17:35 +0300 Subject: [PATCH 6/7] Update docs/tr/docs/async.md Co-authored-by: Hakan Celik --- docs/tr/docs/async.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tr/docs/async.md b/docs/tr/docs/async.md index 5506cc62a09e7..d976eb4783807 100644 --- a/docs/tr/docs/async.md +++ b/docs/tr/docs/async.md @@ -53,7 +53,7 @@ Ancak yukarıdaki adımları takip ederek, bazı performans optimizasyonları ya ## Teknik Detaylar -Python modern versiyonlarında **`async` ve `await`** sözdizimi ile **"coroutines"** kullanan **"asenkron kod"** desteğine sahiptir. +Python'un modern versiyonlarında **`async` ve `await`** sözdizimi ile **"coroutines"** kullanan **"asenkron kod"** desteğine sahiptir. Bu ifadeyi aşağıdaki bölümlerde daha da ayrıntılı açıklayalım: From 98ca4f2b368dd33dd1cae8ee69853a7beaf71d60 Mon Sep 17 00:00:00 2001 From: bilal alpaslan <47563997+BilalAlpaslan@users.noreply.github.com> Date: Wed, 11 Oct 2023 12:59:15 +0000 Subject: [PATCH 7/7] fix few typo --- docs/tr/docs/async.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/tr/docs/async.md b/docs/tr/docs/async.md index d976eb4783807..2be59434350ad 100644 --- a/docs/tr/docs/async.md +++ b/docs/tr/docs/async.md @@ -265,7 +265,6 @@ CPU'ya bağlı işlemlerin yaygın örnekleri, karmaşık matematik işlemleri g Ancak, Makine Öğrenimi sistemlerindekile gibi **CPU'ya bağlı** iş yükleri için paralellik ve çoklu işlemenin (birden çok işlemin paralel olarak çalışması) avantajlarından da yararlanabilirsiniz. -That, plus the simple fact that Python is the main language for **Data Science**, Machine Learning and especially Deep Learning, make FastAPI a very good match for Data Science / Machine Learning web APIs and applications (among many others). Buna ek olarak Python'un **Veri Bilimi**, Makine Öğrenimi ve özellikle Derin Öğrenme için ana dil olduğu gerçeği, FastAPI'yi Veri Bilimi / Makine Öğrenimi web API'leri ve uygulamaları için çok iyi bir seçenek haline getirir. Production'da nasıl oldugunu görmek için şu bölüme bakın [Deployment](deployment/index.md){.internal-link target=_blank}. @@ -290,7 +289,7 @@ async def get_burgers(number: int): return burgers ``` -...instead of `def`: +...`def` yerine: ```Python hl_lines="2" # bu kod asenkron değil