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

Dont always regenerate parsetab #188

Merged
merged 1 commit into from
Apr 9, 2018

Conversation

mhahnenberg
Copy link
Contributor

No description provided.

@mailgun-ci
Copy link

Can one of the admins verify this patch?

setup.py Outdated
@@ -24,7 +24,7 @@
'chardet>=1.0.1',
'cryptography>=0.5',
'idna>=2.5',
'ply>=3.10',
'ply==3.10',
Copy link
Member

Choose a reason for hiding this comment

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

Why is this version pinned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because if the version of PLY were to change then the format of the generated parsetab files could change requiring them to be regenerated.

Copy link
Member

Choose a reason for hiding this comment

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

Pinning version in setup.py is not a good idea. Instead I suggest adding logic that checks if the installed ply version is the one that the tab files were generated with. And if it is not, then regenerate them automatically.

Copy link
Contributor Author

@mhahnenberg mhahnenberg Apr 7, 2018

Choose a reason for hiding this comment

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

Actually I just glanced through the source of PLY and it looks like it checks the version of PLY the previous table was generated with and if it doesn't match the current version then it regenerates the parsetab file. So I don't think we need to pin the version after all.

Copy link
Contributor Author

@mhahnenberg mhahnenberg Apr 7, 2018

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

@mhahnenberg, you are correct that PLY will regenerate the parsetab files if it notices that they're out of date, but the way in which it generates those parsetab files is not safe to do if you have multiple python processes running the same code at the same time. See #206 for more information.

@horkhe horkhe requested review from horkhe and b0d0nne11 April 7, 2018 17:54
@mhahnenberg mhahnenberg force-pushed the dont-always-regenerate-parsetab branch from bd47fa6 to 6335859 Compare April 7, 2018 18:51
@horkhe
Copy link
Member

horkhe commented Apr 7, 2018

Could you please squash the commits to keep the history clean.

@mhahnenberg
Copy link
Contributor Author

Sure thing.

Yacc tries to load the previously generated parsetab.py, but because
we're building a bunch of different parsers with different start tokens
we always fail to load the cached parsetab.py because the signatures
don't match. This diff changes things so that we generate a unique
parsetab.py for each of the different parsers. We also commit these
parsetabs so they don't need to be regenerated at startup when flanker is
imported.
@horkhe
Copy link
Member

horkhe commented Apr 7, 2018

@b0d0nne11 seems reasonable, what do you think? Besides this probably should help with #168.

@mhahnenberg mhahnenberg force-pushed the dont-always-regenerate-parsetab branch from 6335859 to 16c2ba9 Compare April 7, 2018 19:05
@b0d0nne11
Copy link
Contributor

Works for me.

@horkhe horkhe merged commit ae90d93 into mailgun:master Apr 9, 2018
@mhahnenberg
Copy link
Contributor Author

Thank you!

jfly added a commit to jfly/ply that referenced this pull request Sep 21, 2018
The previous implementation had issues with multiple python processes
simultaneously invoking `.yacc(...)` with the same arugments. One of them
could be midway through generating a .py file that the other process
would attempt to import and then crash with a `SyntaxError`. This diff
avoids that problem by instead writing to a tempfile and then atomically
renaming it. This means processes starting up at the same time will both
do the same work, but that's a lot better than having one of them crash!

`flanker` had this issue reported to them in
mailgun/flanker#168 and they attempted to work
around this by committing the parsetab files that ply generates
(mailgun/flanker#188), but this doesn't help if
the user is running a different version of ply than the version that
flanker generated their parsetab files with (because ply will go ahead
and regenerate those files).
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.

5 participants