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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: App comment command execution sequencing #15615

Merged
merged 7 commits into from Nov 10, 2022

Conversation

rlizzo
Copy link
Contributor

@rlizzo rlizzo commented Nov 10, 2022

What does this PR do?

Fixed condition in which app command comments would not execute before the flow is dispatched.

For local runtimes, we executed app comment commands only right before executing a Flow or Work subclass. This is problematic as there are cases where the entrypoint file may make calls to an imported module object in the main file body (either inline or in a class definition), and since the module is not actually available the app would fail to start before it even reached the location where we would have executed the comment commands.

This PR moves up the location of the comment command execution to before the point where the app file is first are loaded into the python runtime.

For Example, this would have previously failed:

# !pip install lmdb
import lightning as L
import lmdb

class Component(L.LightningWork):
    def run(self):
        print('RUN ANY PYTHON CODE HERE')

lmdb.version()  # <--- This bit is problematic since lmdb is not installed yet. 
component = Component()
app = L.LightningApp(component)

While this would have been fine:

# !pip install lmdb
import lightning as L
import lmdb

class Component(L.LightningWork):
    def run(self):
        lmdb.version()  # <--- This would have executed fine since we only reach here after `dispatch()` (whose first step would have executed the comment commands).  
        print('RUN ANY PYTHON CODE HERE')

component = Component()
app = L.LightningApp(component)

With these changes both of the above scenarios now work (as it was originally intended)

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 馃檭

@github-actions github-actions bot added the app Generic label for Lightning App package label Nov 10, 2022
@williamFalcon williamFalcon merged commit bdd2799 into master Nov 10, 2022
69 of 72 checks passed
@williamFalcon williamFalcon deleted the rick/fix-app-comment-command-bug branch November 10, 2022 12:43
@carmocca carmocca added this to the v1.8.x milestone Nov 10, 2022
Borda pushed a commit that referenced this pull request Nov 10, 2022
* fixed condition in which app command comments would not execute before the flow is dispatched

* remove debug print statment

* updated example code

* fix test

* updates to test

Co-authored-by: William Falcon <waf2107@columbia.edu>
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
(cherry picked from commit bdd2799)
lexierule pushed a commit that referenced this pull request Nov 10, 2022
* fixed condition in which app command comments would not execute before the flow is dispatched

* remove debug print statment

* updated example code

* fix test

* updates to test

Co-authored-by: William Falcon <waf2107@columbia.edu>
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
(cherry picked from commit bdd2799)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app Generic label for Lightning App package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants