@@ -18,36 +18,48 @@ pip install queueio
1818Create your routines:
1919
2020``` python
21- # sample.py
21+ # basic.py
22+ from time import sleep as time_sleep
23+
2224from queueio import QueueIO
2325from queueio import routine
2426from queueio.gather import gather
2527from queueio.sleep import sleep
26- from time import sleep as time_sleep
2728
2829
2930@routine (name = " blocking" , queue = " queueio" )
3031def blocking ():
31- pass
32+ time_sleep(0.1 ) # Regular blocking call
33+
3234
3335@routine (name = " yielding" , queue = " queueio" )
3436async def yielding (iterations : int ):
35- pass
37+ # Do them two at a time
38+ for _ in range (iterations // 2 ):
39+ await gather(blocking(), blocking())
40+ await sleep(0.2 ) # Release processing capacity
41+ if iterations % 2 == 1 :
42+ await blocking()
3643
3744
3845if __name__ == " __main__" :
39- QueueIO().submit(yielding())
46+ q = QueueIO()
47+ try :
48+ q.submit(yielding(7 ))
49+ finally :
50+ q.shutdown()
51+
4052```
4153
4254Add the configuration to your ` pyproject.toml ` :
4355
4456``` toml
4557[tool .queueio ]
4658# Configure RabbitMQ
47- broker = ' pika://guest:guest@localhost:5672/'
48- journal = ' pika://guest:guest@localhost:5672/'
59+ broker = " pika://guest:guest@localhost:5672/"
60+ journal = " pika://guest:guest@localhost:5672/"
4961# Register the modules that the worker should load to find your routines
50- register = [" sample " ]
62+ register = [" basic " ]
5163```
5264
5365The broker and journal can be configured with environment variables
@@ -61,7 +73,7 @@ QUEUEIO_JOURNAL='amqp://guest:guest@localhost:5672/'
6173Run your script to submit the routine to run on a worker:
6274
6375``` sh
64- python sample .py
76+ python basic .py
6577```
6678
6779Then run the worker to process submitted routines:
@@ -83,4 +95,4 @@ This is a new project.
8395The design of the public API is under active development and subject to change.
8496Release notes will provide clear upgrade instructions,
8597but backward compatibility and deprecation warnings
86- will not generally be implemented.
98+ will not generally be implemented.
0 commit comments