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

Tournaments can run on Windows #721

Merged
merged 24 commits into from
Sep 21, 2016
Merged

Tournaments can run on Windows #721

merged 24 commits into from
Sep 21, 2016

Conversation

drvinceknight
Copy link
Member

Started with #719 but has a bit more:

  • Have added the ability to keep everything in memory: currently this is the default and temporary files are not used at all but I want to think about that some more (might be more efficient to keep the temporary files as default unless we're on windows which we could just detect and in that case keep things in memory). I'm not overly exited with the fix in Fix for temporary files on windows. #713 as it risks keeping files around if anything is interrupted...
  • There are some tests for the above that I need to write ideally.
  • Have just skipped the parallel processing tests if on windows (have also skipped testing 2.7 and 3.4 on windows because life is short and they were throwing weird bugs). I feel happier to say that parallel processing is not supported on Windows than making hacky changes...

I believe this will pass all CI tests... Heading to bed: will work on some more tomorrow :)

@meatballs
Copy link
Member

I feel happier to say that parallel processing is not supported on Windows than making hacky changes...

Agreed - we could even wrap the parallel processing in a condition that checks the os

@drvinceknight
Copy link
Member Author

we could even wrap the parallel processing in a condition that checks the os

Good call, will put something like that together now :) 👍

@drvinceknight drvinceknight changed the title WIP Do Not Merge (Windows fixes amongst other things) Tournaments can run on Windows Sep 21, 2016
@drvinceknight
Copy link
Member Author

I think this is in good shape for a review now:

  • Have added an in_memory variable to tournament.play. Default is False, if True it basically just uses an internal interactions dictionary.
  • Have added a axelrod.on_windows that on loading of the library detects if it's running on a Windows machine.
  • If running on a windows machine and no filename is provided then in_memory will automatically be set to True. This is because NamedTemporaryFiles are not very useful on Windows (see this known bug: https://bugs.python.org/issue14243).
  • I have added test skips, basically dropping support for parallel processing on Windows. There were other bugs that @Ducksual found with parallel processing: I have opened Fix parallel processing on windows #718 and suggest that that's fixed as a separate issue.

Have added some tests and also a short documentation tutorial about parallel processing.

I suggest that once this is OK'd and in:

  • We make a note on Fix parallel processing on windows #718 to say that once it's fixed we fix the docs which in two places would say that parallel processing is not supported on Windows.
  • We open an issue to refactor ResultSet so that it's as efficient as ResultSetFromFile. Currently it reads the dictionary more often than it needs to. This shouldn't be hard: everything is basically already in place in ResultSetFromFile, that just needs to be tweaked so that it worked with a dictionary.

@meatballs
Copy link
Member

What about the wrapping of the parallel processing in a condition so that it only happens if not windows?

@drvinceknight
Copy link
Member Author

What about the wrapping of the parallel processing in a condition so that it only happens if not windows?

Yup: I missed that (thought I had done it), appveyor just pointed it out. Just pushing that now :)

@@ -1,4 +1,7 @@
from __future__ import absolute_import
import sys

on_windows = sys.platform.startswith("win")
Copy link
Member

@meatballs meatballs Sep 21, 2016

Choose a reason for hiding this comment

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

Any reason you've gone with sys.platform rather than os.name?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not an educated reason: would os.name be better? I have to check for nt or something like that right?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool: I'll change that 👍

Copy link
Member

Choose a reason for hiding this comment

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

but I wondered if you knew something that I don't !!

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope: I just got scared away by the nt :) Have changed this with 72238a3

@meatballs
Copy link
Member

Big 👍 from me for this one. That was a painful day....

@DavidCEllis
Copy link
Contributor

I don't know what you're talking about. Windows is easy! ;-)

In all seriousness I tried to be fairly careful to clean up the files but it would have been really nice if NamedTemporaryFile actually did something useful in Windows (or if TemporaryDirectory had existed before Python 3.2).

Multiprocessing on windows is a separate nightmare.

@drvinceknight
Copy link
Member Author

In all seriousness I tried to be fairly careful to clean up the files but it would have been really nice if NamedTemporaryFile actually did something useful in Windows (or if TemporaryDirectory had existed before Python 3.2).

You had done a great job, and it's highly appreciated. You figured out all the bugs 👍

Multiprocessing on windows is a separate nightmare.

We'll get there eventually (hopefully)!

Either way hopefully this will all be in place so that you could contribute actual Game Theory next :)

@DavidCEllis
Copy link
Contributor

I actually checked and NamedDirectory wouldn't have helped (at least in cleaning up the files on windows). As far as I can tell the implementation of NamedTemporaryFile on windows with the locking behaviour is the only way to guarantee the file will be deleted. Without locking something else could open the file and then Windows wouldn't allow it to be removed.

Copy link
Member

@marcharper marcharper left a comment

Choose a reason for hiding this comment

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

Although this is good work, I'm not a fan of this kind of thing -- I doubt many windows users would use the library without a GUI and it makes the code more complex to maintain -- but I won't stand in the way.

Has anyone tested the library with bash on windows? That might be a better way to have some support on windows, and who knows, maybe multiprocessing works?

@@ -1,10 +1,11 @@
environment:
matrix:
- PYTHON: "C:\\Python27"
- PYTHON: "C:\\Python34"
#- PYTHON: "C:\\Python27"
Copy link
Member

Choose a reason for hiding this comment

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

Can we delete these if they won't be used?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup.

Copy link
Member Author

Choose a reason for hiding this comment

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

Have pushed that.

@@ -34,9 +33,9 @@ def test_full_tournament(self):
tournament = axelrod.Tournament(name='test', players=strategies,
game=self.game, turns=2,
repetitions=2)
tmp_file = tempfile.NamedTemporaryFile()
filename = "test_outputs/test_tournament.csv"
Copy link
Member

Choose a reason for hiding this comment

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

Are we going to run into issues if the directory doesn't exist?

Copy link
Member Author

Choose a reason for hiding this comment

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

The directory should exist, I've put a README.md file in there so cloning the library should put it there right?

@@ -93,11 +102,15 @@ def play(self, build_results=True, filename=None,
self.progress_bar = tqdm.tqdm(total=len(self.match_generator),
desc="Playing matches")

self.setup_output_file(filename)
if on_windows and (filename is None):
Copy link
Member

Choose a reason for hiding this comment

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

So if the tournament takes up a lot of memory on windows, it won't work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup: it it takes up a lot of memory then it will crash. It will work fine if a filename is provided though.

@drvinceknight
Copy link
Member Author

I doubt many windows users would use the library without a GUI and it makes the code more complex to maintain

I know of 3 that have (with anaconda, Jupyter etc I actually would hope we would not close the door on windows users). I expect I'll have students doing so too. Important to get it working natively on windows even if it does make it harder for us.

Has anyone tested the library with bash on windows? That might be a better way to have some support on windows, and who knows, maybe multiprocessing works?

That's not really running on Windows though. I expect that if it runs on bash it might not pick up the on_windows flag? Apparently that's a full ubuntu thing? (I have no idea).

@meatballs
Copy link
Member

I doubt many windows users would use the library without a GUI

Several of the students who came to the sprint were on windows - and I suspect that's often the case for young undergrads coming to university with their shiny new laptops!

@DavidCEllis
Copy link
Contributor

Bash on windows is Ubuntu related - but still beta and a little more work to install than Anaconda. I'm not sure if all the Linux features would work on it or not but I'm installing it now so I can find out.

@drvinceknight
Copy link
Member Author

drvinceknight commented Sep 21, 2016

Bash on windows is Ubuntu related - but still beta and a little more work to install than Anaconda. I'm not sure if all the Linux features would work on it or not but I'm installing it now so I can find out.

Thanks @Ducksual: that's helpful.

Either way I think that in the interest of EDIT diversity inclusivity we should work to offer native support. This PR is a first step there, we can always open more PRs to improve it and reduce the complexity :)

@drvinceknight
Copy link
Member Author

I'm installing it now so I can find out.

@Ducksual it would be interesting to know what the following does on bash for windows...:

>>> import os
>>> os.name

@DavidCEllis
Copy link
Contributor

DavidCEllis commented Sep 21, 2016

>>> import os
>>> os.name
'posix'
>>>

@drvinceknight
Copy link
Member Author

Neat :)

@DavidCEllis
Copy link
Contributor

It's kind of neat but a little intimidating if you haven't used linux/bash before. After changing your machine to developer mode and going through the install you still don't have any gui support for linux.

@drvinceknight
Copy link
Member Author

It's kind of neat but a little intimidating if you haven't used linux/bash before.

Oh absolutely. Bash for windows isn't really a solution. I was just curious :)

@drvinceknight
Copy link
Member Author

drvinceknight commented Sep 21, 2016

Bash for windows isn't really a solution.

Although it might be for some people as it looks like you would be able to run parallel tournaments with it.

It's good to know.

@marcharper
Copy link
Member

marcharper commented Sep 21, 2016

Thanks @Ducksual @drvinceknight @meatballs ! Great work everyone.

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.

None yet

4 participants