question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document async def interfaces for signals

See original GitHub issue

It’d be nice to mention async def approach in https://docs.scrapy.org/en/latest/topics/signals.html#deferred-signal-handlers, and maybe even rewrite the example to it.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Gallaeciocommented, Mar 12, 2021

@codeslash21 Sure.

Scrapy uses Twisted, which has a class called Deferred, which is used to implement asynchronous code. You may find more information about them in the Twisted documentation, but it’s a complex topic, and full understanding is not needed for this task, I think.

However, Twisted also allows to write code using Python coroutines, also known as async def syntax. The code still uses deferreds underneath, but its use is transparent to users, and the resulting code is more readable.

We actually have this covered in the documentation of Scrapy, at https://docs.scrapy.org/en/latest/topics/coroutines.html, with a good example of how a piece of code looks with Deferreds, and how the same code can be rewritten with coroutine syntax.

If you manage to understand that example, I think you should be able to handle this task, which would consist of:

  1. Adding a second paragraph to https://docs.scrapy.org/en/latest/topics/signals.html#deferred-signal-handlers that mentions that you can also use coroutines, with a link to the coroutine topic.
  2. Changing the example to use coroutines instead of deferreds, for better readability.
0reactions
burakcankcommented, May 10, 2021

Can I take this issue please ? I have been working on this one for almost a day now, trying to learn my way around coroutines and deferred objects.

Read more comments on GitHub >

github_iconTop Results From Across the Web

signal — Set handlers for asynchronous events ... - Python Docs
Source code: Lib/signal.py This module provides mechanisms to use signal handlers in Python. General rules: The signal.signal() function allows defining ...
Read more >
asyncdbus - PyPI
The Client Interface​​ To use a service on the bus, the library constructs a proxy object you can use to call methods, get...
Read more >
Signals (System Interface Guide)
Signals can be synchronously generated by an error in an application, such as SIGFPE and SIGSEGV, but most signals are asynchronous.
Read more >
Asyncio API — python-sdbus documentation - Read the Docs
Signal when existing object or and interface of existing object is removed. Signal data is: Object pathstr. Path to object that was removed...
Read more >
Asynchronous and non-Blocking I/O - Tornado Web Server
Callback registry (e.g. POSIX signals). Regardless of which type of interface is used, asynchronous functions by definition interact differently with their ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found