Skip to content

Commit

Permalink
Fix eventlet example from not running.
Browse files Browse the repository at this point in the history
  • Loading branch information
Galdanwing authored and auvipy committed Apr 26, 2022
1 parent ab2bcc0 commit 4fe9d8b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
6 changes: 2 additions & 4 deletions examples/eventlet/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ This is a Celery application containing two example tasks.
First you need to install Eventlet, and also recommended is the `dnspython`
module (when this is installed all name lookups will be asynchronous)::

$ pip install eventlet
$ pip install dnspython
$ pip install requests
$ python -m pip install eventlet celery pybloom-live

Before you run any of the example tasks you need to start
the worker::
Expand All @@ -34,7 +32,7 @@ of the response body::
$ cd examples/eventlet
$ python
>>> from tasks import urlopen
>>> urlopen.delay('http://www.google.com/').get()
>>> urlopen.delay('https://www.google.com/').get()
9980

To open several URLs at once you can do::
Expand Down
1 change: 0 additions & 1 deletion examples/eventlet/celeryconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

broker_url = 'amqp://guest:guest@localhost:5672//'
worker_disable_rate_limits = True
result_backend = 'amqp'
result_expires = 30 * 60

imports = ('tasks', 'webcrawler')
5 changes: 3 additions & 2 deletions examples/eventlet/tasks.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import requests

from celery import task
from celery import shared_task


@task()
@shared_task()
def urlopen(url):
print(f'-open: {url}')
try:
response = requests.get(url)
except requests.exceptions.RequestException as exc:
print(f'-url {url} gave error: {exc!r}')
return
return len(response.text)
6 changes: 3 additions & 3 deletions examples/eventlet/webcrawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import requests
from eventlet import Timeout
from pybloom import BloomFilter
from pybloom_live import BloomFilter

from celery import group, task
from celery import group, shared_task

try:
from urllib.parse import urlsplit
Expand All @@ -43,7 +43,7 @@ def domain(url):
return urlsplit(url)[1].split(':')[0]


@task(ignore_result=True, serializer='pickle', compression='zlib')
@shared_task(ignore_result=True, serializer='pickle', compression='zlib')
def crawl(url, seen=None):
print(f'crawling: {url}')
if not seen:
Expand Down

0 comments on commit 4fe9d8b

Please sign in to comment.