0Pricing
MCP Academy · درس

أدوات غير متزامنة لا تحجب التنفيذ

استخدموا الإدخال والإخراج غير المتزامنين لخدمة عدة استدعاءات في الوقت نفسه.

أدوات غير متزامنة لا تحجب التنفيذ درس مجاني في MCP Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في MCP Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة MCP Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

One Slow Tool, Everyone Waits

If a tool does slow work synchronously, it blocks the whole server, so every other call has to wait its turn. ⏳

Most Slowness Is Waiting

A tool that calls a database or API spends most of its time on I/O, just waiting for a reply rather than using the CPU.

Async Frees the Server

Marking a tool async lets the server handle other requests during that wait, instead of sitting idle on one call.

Define an async def Tool

Declare your handler with async def and FastMCP will await it, so the event loop can serve other work meanwhile.

@mcp.tool()
async def fetch(city: str) -> str:
    ...

await Your I/O Calls

Inside an async tool, use await on async libraries so each pause hands control back to the loop instead of freezing it.

data = await client.get(url)
return data.text

Use Async-Native Libraries

Reach for clients like httpx or asyncpg. They are built to await, unlike blocking libraries that stall the whole loop.

Never Block the Event Loop

A plain time.sleep or a heavy loop blocks every other request. In async code, blocking calls quietly freeze the server.

Offload Heavy CPU Work

For real CPU crunching, push it to a thread with asyncio.to_thread so the event loop stays free to serve calls.

result = await asyncio.to_thread(crunch, data)

Run Calls Concurrently

Need several fetches at once? asyncio.gather runs awaitables together, finishing far faster than awaiting each in turn.

a, b = await asyncio.gather(get(x), get(y))

Add a Timeout to Awaits

Wrap slow awaits in a timeout so one stuck upstream cannot tie up a request forever and starve the server.

Async Scales Concurrency

With async I/O, one process can juggle many in-flight calls at once, so your server stays responsive under real load.

Quick Check

Why does async I/O help a busy MCP server?

Recap: Don't Block

You made tools async, awaited I/O, offloaded CPU work, and ran calls together, so one slow tool no longer freezes the server. 🚀

الأسئلة الشائعة

هل درس «أدوات غير متزامنة لا تحجب التنفيذ» مجاني؟

نعم — نص درس «أدوات غير متزامنة لا تحجب التنفيذ» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة MCP Academy، انتقل إلى CoddyKit PRO. تتضمن دورة MCP Academy 4 دروس في المجموع.

ماذا ستتعلم في «أدوات غير متزامنة لا تحجب التنفيذ»؟

استخدموا الإدخال والإخراج غير المتزامنين لخدمة عدة استدعاءات في الوقت نفسه. تتمرن على MCP Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ MCP Academy؟

لا تُشترط خبرة سابقة. MCP Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «أدوات غير متزامنة لا تحجب التنفيذ»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس MCP Academy هذا؟

نعم. كل درس في MCP Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. أدوات غير متزامنة لا تحجب التنفيذ
  2. التزامن والتحكم في التدفق العكسي
  3. تقليص النتائج كثيفة الرموز المميّزة
  4. التوسع الأفقي باستخدام الجلسات
← العودة إلى MCP Academy