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

Switch to use sync version of CPython setup/installation method #11428

Merged
merged 4 commits into from
Jan 27, 2021

Conversation

QilongTang
Copy link
Contributor

@QilongTang QilongTang commented Jan 26, 2021

Please Note:

  1. Before submitting the PR, please review How to Contribute to Dynamo
  2. Dynamo Team will meet 1x a month to review PRs found on Github (Issues will be handled separately)
  3. PRs will be reviewed from oldest to newest
  4. If a reviewed PR requires changes by the owner, the owner of the PR has 30 days to respond. If the PR has seen no activity by the next session, it will be either closed by the team or depending on its utility will be taken over by someone on the team
  5. PRs should use either Dynamo's default PR template or one of these other template options in order to be considered for review.
  6. PRs that do not have one of the Dynamo PR templates completely filled out with all declarations satisfied will not be reviewed by the Dynamo team.
  7. PRs made to the DynamoRevit repo will need to be cherry-picked into all the DynamoRevit Release branches that Dynamo supports. Contributors will be responsible for cherry-picking their reviewed commits to the other branches after a LGTM label is added to the PR.

Purpose

Regarding https://jira.autodesk.com/browse/REVIT-173181.

Switch to use sync version of CPython setup/installation method as suggested by @mmisol .

ALittleHangInstallingCpython

If team is OK with this, let's ship the hotfix this way. Notice the little hang only happens first time user trying to evaluate a CPython node

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated

Reviewers

@DynamoDS/dynamo

FYIs

@mmisol @mjkkirschner @saintentropy

Task.Run(() => {
Python.Included.Installer.SetupPython().Wait();
isPythonInstalled = true;
}).Wait();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey Aaron. I must admit when I heard about the hang I remember I also happened to experience it. Back then, what I did to get rid of it is to make SetupPython fully synchronous, which is actually a simple change in our Python.Included fork https://git.autodesk.com/Dynamo/pythonnet/pull/14/files#diff-4cc075ba367f8ff85f7aff06fd5c060aR30. That change didn't make it into master because it was part of the draft for Python module installation support, which is still a RFC.
IMO, making SetupPython synchronous is a simpler solution. Besides, since the unzip action is almost instantaneous and runs only once it doesn't make much sense for it to be async. That would mean that we would just call Python.Included.Installer.SetupPython(); here.
An alternative, if we don't want to change the existing SetupPython function, could be to create a synchronous variation named SetupPythonSync that basically uses the same code I linked.
What do you think about this @QilongTang @mjkkirschner ?

Copy link
Member

Choose a reason for hiding this comment

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

I like adding the new method!

Copy link
Member

@mjkkirschner mjkkirschner Jan 26, 2021

Choose a reason for hiding this comment

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

what do you guys think about actually wrapping pythonIncluded in our own namespace? I guess I am concerned that if we need custom functionality that and if a regular build of Python.Included were loaded into Revit's process by another addin (pyrevit) we would hit a missing method exception.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we could do that but not sure if now is a good time, given it would represent a breaking change. Python .NET could also potentially present clashes. Not sure if we have tested Revit + pyRevit + Dynamo, but we should probably do it to have an idea of how urgent this change should be. What do you think @mjkkirschner ?

Copy link
Member

Choose a reason for hiding this comment

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

@mmisol I'm fine waiting as well and we can discuss those changes together instead - but I am curious - in what sense is it a breaking change?

Copy link
Contributor Author

@QilongTang QilongTang Jan 26, 2021

Choose a reason for hiding this comment

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

@mmisol I'm fine with that, I will make that change in this PR soon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @mmisol You just reminded me, we tried that yesterday and found we need to wait for the unzip to finish before executing the graph. If we just call Python.Included.Installer.SetupPython(); the install code in our PythonNet is async so user will get this error
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mjkkirschner Changing the namespace of a public class is technically a breaking change. Probably no-one is using it directly except us, so it could be low risk.

@QilongTang We don't just need a change in Dynamo, but we also need to change Python.Included. If you check the link I shared earlier you'll see the SetupPython function was changed to being synchronous, though It's probably best if we add a new one named SetupPythonSync and leave SetupPython unchanged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mmisol Cool. Go ahead for that

@mjkkirschner
Copy link
Member

This also needs to consume the new binary right? (I think manually copy to extern)

@QilongTang QilongTang changed the title Use task run to wrap the CPython installation body Switch to use sync version of CPython setup/installation method Jan 26, 2021
@QilongTang
Copy link
Contributor Author

QilongTang commented Jan 26, 2021

This also needs to consume the new binary right? (I think manually copy to extern)

Indeed, @mmisol helped #11429

@mmisol
Copy link
Collaborator

mmisol commented Jan 26, 2021

@QilongTang Could you search for SetupPython().Wait in the code base? I'm pretty sure this was being done someplace else. It would be nice to make the fix there too.

@QilongTang QilongTang marked this pull request as ready for review January 26, 2021 22:54
Copy link
Collaborator

@mmisol mmisol left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks!

@QilongTang QilongTang merged commit 969e347 into master Jan 27, 2021
@QilongTang QilongTang deleted the TestBranch branch January 27, 2021 16:04
QilongTang added a commit that referenced this pull request Jan 27, 2021
* Use task run to wrap the installation body

* Update to use sync version of API

* Additional place to fix
QilongTang added a commit that referenced this pull request Jan 27, 2021
…) (#11435)

* Switch to use sync version of CPython setup/installation method (#11428)

* Use task run to wrap the installation body

* Update to use sync version of API

* Additional place to fix

* Update Python.Included to PR 22 (#11429)

Adds function SetupPythonSync to setup python synchronously

Co-authored-by: Martin Misol Monzo <[email protected]>
@QilongTang QilongTang restored the TestBranch branch February 1, 2021 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants