Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added documentation regarding corutines #391

Closed
wants to merge 5 commits into from
Closed

Added documentation regarding corutines #391

wants to merge 5 commits into from

Conversation

07pepa
Copy link

@07pepa 07pepa commented Oct 13, 2020

  • added documentation
  • removed trailing spaces

This closes #388

@coveralls
Copy link

coveralls commented Oct 13, 2020

Coverage Status

Coverage remained the same at 99.699% when pulling 5b04560 on 07pepa:coro into 6eb0b53 on dbader:master.

@07pepa
Copy link
Author

07pepa commented Oct 13, 2020

it looks like coverage is buggy...

@07pepa
Copy link
Author

07pepa commented Mar 19, 2021

i decided it is not as dependend on #357 and can be fast forwarded

@07pepa
Copy link
Author

07pepa commented Mar 19, 2021

@SijmenHuizenga can we Merge this?... any objections are welcomed :)

Copy link
Collaborator

@SijmenHuizenga SijmenHuizenga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this pr! I learnt some things from it 😄

The goal of the schedule documentation is to teach people how to use the schedule library. We are not in the business of explaining how asyncio works or state the advantages of using coroutines.

At the moment the code and text has too many details that are interesting, but not relevant to the schedule docs. I've added some comments to explain my thinking. Let me know if anything is unclear.

During reading and testing I have updated the page to how I see it. I will submit those changes in a separate pr to your branch so that you can decide if you want to include those changes into this pr.

This code will only run on Wednesday regular task and Sunday coroutine task.
Nothing is running in between but code not hangs on system signals and exits loop (on one thread that is impossible without coroutines).

.. code-block:: python
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example code has many good things in it. I think if we split up the example in a few shorter examples it becomes easier to understand.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

docs/faq.rst Outdated

Does schedule support coroutines?
-------------------------------
:doc:`yes <async-support>`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:doc:`yes <async-support>`
Schedule does not accept coroutines as jobs directly. However, using using ``asyncio.create_task`` you able to schedule async jobs. See :doc:`this page <async-support>` for an example.

@@ -0,0 +1,92 @@
Nonblocking scheduling with coroutines
======================================
Fist is good to explain what we mean by nonblocking scheduling.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to focus on how the schedule library interacts with the asyncio Python module. The concept 'non-blocking scheduling' is not so much equal to asyncio... One could achieve non-blocking job execution without asyncio and asyncio can (in some cases) sill be blocking.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is true!....


DrawBacks
----------
Only drawback is precision of asyncio.wait_for timeout.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate how this affects job scheduling?

Copy link
Author

@07pepa 07pepa Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well i saw some variance in my personal project (few seconds) and real amount of "sleep" is better known for time.sleep https://stackoverflow.com/questions/1133857/how-accurate-is-pythons-time-sleep

so job can be executed later then expected but that is also expected for time.sleep it is not exact

global terminateEvent
terminateEvent = asyncio.Event() #needs to run on asyncio loop

def terminate(signum):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we have here is a quite a generic signal handler. It seems like a good implementation, but it doesn't have much to do with the library. Therefore I don't think this should be part of the schedule library documentation.

I also don't remember seeing any questions (in issues) regarding interrupting time.sleep. Apparently it works out-of-the-box for most people. If this changes I would be happy to help write a dedicated page on this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time sleep and asyncio sleep are fine on their own

but when you use your custom sigal handler they dont recive KeyboardInterrupt

and if you want your code to finish corectly you should use them

but in that case you must have something that can be interupted

and you can reference back to issue i created....#388

i think we should put this as seperate example

Josef and others added 3 commits April 10, 2021 23:40
added documentation regarding scheduling task and corutines in non-blocking loop
@07pepa
Copy link
Author

07pepa commented Apr 28, 2021

@SijmenHuizenga it is better now?

@SijmenHuizenga
Copy link
Collaborator

I'm sorry for making you wait this long on a response.

The docs should focus on explaining how the schedule library works and how to use it. The examples about interrupting a loop and handling signals are out of scope. These examples mostly teach the reader about Python and asyncio without teaching much about the schedule library. These examples would fit very well in a blog post or in a Github gist, but not so much in the official docs.

I just pushed the shortened examples and will merge this pr soon.

Thank you for working on these examples, I learnt some new things and I expect many people will too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add corutine based loop/sleep to documentation
3 participants