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

Replace pip2/3-lock with a generic sage-flock command #23397

Closed
embray opened this issue Jul 10, 2017 · 37 comments
Closed

Replace pip2/3-lock with a generic sage-flock command #23397

embray opened this issue Jul 10, 2017 · 37 comments

Comments

@embray
Copy link
Contributor

embray commented Jul 10, 2017

I suggested something like this on #21672 but didn't have immediate need to follow up on it.

Something like this will be useful for making Windows builds more reliable, however, as there are some operations that can fail if they are run simultaneously during parallel builds.

In particular I'm trying to trace down failures with DLL rebasing, and at least part of the problem is that rebase can fail if it's being multiple times simultaneously as can happen during a parallel build (especially toward the end of the build when lots of Python packages are being installed--these are fast and often results in multiple rebases being run simultaneously).

With tickets like #22509 it will also be possible to make further restrictions, such as not running rebase while a package is being uninstalled.

CC: @jdemeyer

Component: build

Author: Erik Bray

Branch/Commit: b6e4a62

Reviewer: Jeroen Demeyer

Issue created by migration from https://trac.sagemath.org/ticket/23397

@embray embray added this to the sage-8.1 milestone Jul 10, 2017
@embray
Copy link
Contributor Author

embray commented Jul 10, 2017

Author: Erik Bray

@embray
Copy link
Contributor Author

embray commented Jul 10, 2017

Commit: 63f4b2d

@embray
Copy link
Contributor Author

embray commented Jul 10, 2017

Branch: u/embray/build/lockfile

@embray
Copy link
Contributor Author

embray commented Jul 10, 2017

comment:1

(CC: jdemeyer, original author of the script)


New commits:

63f4b2dAdds a new sage-flock command based on the original pip2-lock command, but generalized to

@embray
Copy link
Contributor Author

embray commented Sep 6, 2017

comment:2

Apparently this has a bug...

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 6, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

5e89b68argparse.FileType can be handy, but it doesn't create directories.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 6, 2017

Changed commit from 63f4b2d to 5e89b68

@embray
Copy link
Contributor Author

embray commented Oct 19, 2017

comment:5

ping

I actually increasingly need this as it's difficult to get through a parallel build on Cygwin now without it failing a few times due to the lack of locking around rebase.

@jdemeyer
Copy link

comment:6

Why did you remove sys.stderr.flush()?

@jdemeyer
Copy link

Reviewer: Jeroen Demeyer

@jdemeyer
Copy link

comment:7

I think it would be good to mention somewhere in a comment that this may be used in build scripts, but only for packages depending on Python.

The help mentions

The command may also be a Python module in which case it is run in the same
Python interpreter as this script (a small optimization to avoid restarting the
Python interpreter).

but I don't see that in the implementation.

@jdemeyer
Copy link

comment:8

Replying to @jdemeyer:

Why did you remove sys.stderr.flush()?

See also https://mail.python.org/pipermail/python-list/2015-November/698421.html

It seems that Python 2 has unbuffered sys.stderr by default, which means that the flushing is not needed.

But this was changed in Python 3, so the flushing would be required there.

@embray
Copy link
Contributor Author

embray commented Oct 25, 2017

comment:9

Ah, good catch. I had mistakenly assume that the print() function would automatically flush by default.

As for being "only for packages depending on Python" that has me wondering now what the best thing would be to do with this. Maybe it should be moved to build/bin. I need to use it for basically all packages, and the fact that it uses Python is not an impediment to that, since build tools are allowed to use the system Python (and in fact require it). But this script is also used at runtime (just for pip install, currently), in which case it should use Sage's Python. Any ideas?

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 25, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

60c7670removed false statement from the docstring
e960c8aTurns out print() does not flush I/O by default

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 25, 2017

Changed commit from 5e89b68 to e960c8a

@jdemeyer
Copy link

comment:11

Replying to @embray:

the fact that it uses Python is not an impediment to that, since build tools are allowed to use the system Python (and in fact require it).

If I recall correctly, we require system Python 2.6 or later, which means that you can't use argparse.

@jdemeyer
Copy link

comment:12

Replying to @sagetrac-git:

e960c8a Turns out print() does not flush I/O by default

The flush keyword is Python 3 only.

@embray
Copy link
Contributor Author

embray commented Oct 25, 2017

comment:13

D'oh, how annoying. In that case I'll just switch it back to sys.stderr.write....

@embray
Copy link
Contributor Author

embray commented Oct 25, 2017

comment:14

Replying to @jdemeyer:

Replying to @embray:

the fact that it uses Python is not an impediment to that, since build tools are allowed to use the system Python (and in fact require it).

If I recall correctly, we require system Python 2.6 or later, which means that you can't use argparse.

That's not an issue. We already addressed this some time ago... https://github.com/sagemath/sagetrac-mirror/blob/develop/build/sage_bootstrap/compat?id=3faf8d0519918feb308b3bb56fbe36e0a0c2a290

The question is, should the script live in build/bin or src/bin, and what should go in the shebang line? This is unclear for Python scripts that we want to work at build time and run time...

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 25, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

6e3333dAnnoyingly, the flush kwarg for the print_function does not exist in Python 2...

@jdemeyer
Copy link

comment:16

Replying to @embray:

I need to use it for basically all packages

What is your use case?

@embray
Copy link
Contributor Author

embray commented Oct 25, 2017

comment:17

See description.

@embray
Copy link
Contributor Author

embray commented Oct 25, 2017

comment:18

To clarify, the sage-rebase command opens, and often writes to, every DLL installed in $SAGE_LOCAL. It is run at the end of every package build. If two packages complete build/installation at the same time, then there is a race to run sage-rebase, and the second one can fail, causing the build to halt. This especially happens while installing the Python packages because there are a large number of packages being installed quickly one after the other. But it can happen (and has happened) in principle any other time. So I need to put a lock around sage-rebase to prevent it from being run simultaneously for multiple packages.

@jdemeyer
Copy link

comment:19

Replying to @embray:

what should go in the shebang line?

If you intend to use the system Python if applicable, it should be #!/usr/bin/env python.

@embray
Copy link
Contributor Author

embray commented Oct 25, 2017

comment:20

Replying to @jdemeyer:

Replying to @embray:

what should go in the shebang line?

If you intend to use the system Python if applicable, it should be #!/usr/bin/env python.

But that's the problem, because if it's intended to be used at runtime it should in that case be using Sage's Python (I guess?), and with SAGE_PYTHON3=yes this is incorrect since python still means python2.7.

That said, the original use case for this was with pip, and running pip is still arguably a "build" action, so maybe this should just be moved to build/bin to emphasize that it's a build tool. It can use the system python by default and/or Sage's Python 2 because ultimately it doesn't matter what Python this is run with since it just execs the program it wraps.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 25, 2017

Changed commit from 6e3333d to 3ec24bc

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 25, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

3ec24bcMoved to build/bin to emphasize that this is primarily a build utility (under its current use cases).

@embray
Copy link
Contributor Author

embray commented Oct 25, 2017

comment:22

You've convinced me (and/or I've convinced myself) that this is the best approach.

@jdemeyer
Copy link

comment:23

Replying to @embray:

That's not an issue. We already addressed this some time ago... https://github.com/sagemath/sagetrac-mirror/blob/develop/build/sage_bootstrap/compat?id=3faf8d0519918feb308b3bb56fbe36e0a0c2a290

But then you need to ensure that your script can find this argparse module.

@embray
Copy link
Contributor Author

embray commented Oct 25, 2017

comment:24

Okay, I was under the mistaken assumption, for some reason, that this was added to PYTHONPATH during builds.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 26, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

18f9454Move the contents of sage-flock into the sage_bootstrap package itself, and replace the sage-flock script with a boilerplate script to import and run it from sage_bootstrap

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 26, 2017

Changed commit from 3ec24bc to 18f9454

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 31, 2017

Changed commit from 18f9454 to b6e4a62

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 31, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

b6e4a62Merely being part of the sage_bootstrap package doesn't mean we don't still have to manually try to import argparse from the bundled compat module

@embray
Copy link
Contributor Author

embray commented Nov 14, 2017

comment:29

This is increasingly critical since not having it can lead to failures even in the patchbot base build, causing the patchbot to exit.

@vbraun
Copy link
Member

vbraun commented Dec 11, 2017

Changed branch from u/embray/build/lockfile to b6e4a62

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

No branches or pull requests

3 participants