Skip to content

Fixes to io.ascii fast reader when used in multiprocessing 'spawn' mode - #8853

Merged
saimn merged 11 commits into
astropy:masterfrom
astrofrog:fix-io-ascii-38
Jun 17, 2019
Merged

saimn merged 11 commits into
astropy:masterfrom
astrofrog:fix-io-ascii-38

Conversation

@astrofrog

@astrofrog astrofrog commented Jun 15, 2019 •

Copy link
Copy Markdown
Member

This is a partial fix for #8851 but it might be worth already getting these changes in master, as I believe they are correct and will be needed whatever the full fix is. Basically it looks like the call to CParser in __reduce__ used an old API. With these changes, the example shown in #8851 works but there are still memory deallocation warnings and issues with performance - but I think those could be dealt with in a separate PR.

Unfortunately I don't really know what the best way is to test this automatically since the multiprocessing starting mode has to be set globally. This will effectively get tested implicitly once we start to have Python 3.8 MacOS X builds.

fill_exclude_names=None,
fill_extra_cols=0,
fast_reader=True):
fast_reader=None):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The default True would have never worked since we pop it below!

@pllim

pllim commented Jun 15, 2019

Copy link
Copy Markdown
Member

Does this mean we don't need #8852 after all? Wow, great investigation!

@codecov

codecov Bot commented Jun 15, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #8853 into master will increase coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8853      +/-   ##
==========================================
+ Coverage      87%   87.02%   +0.02%     
==========================================
  Files         401      402       +1     
  Lines       59496    59625     +129     
  Branches     1100     1100              
==========================================
+ Hits        51763    51889     +126     
- Misses       7092     7095       +3     
  Partials      641      641
Impacted Files Coverage Δ
astropy/visualization/__init__.py 100% <0%> (ø) ⬆️
astropy/visualization/time.py 97.65% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b8933a...0e82791. Read the comment docs.

@astropy astropy deleted a comment from codecov Bot Jun 15, 2019
@astrofrog

astrofrog commented Jun 15, 2019 •

Copy link
Copy Markdown
Member Author

@pllim - for now we would still need #8852 because this is only a partial fix - there are still memory allocation issues and the tests run very slowly. But this does get rid of the exceptions.

@astrofrog

Copy link
Copy Markdown
Member Author

I've now identified the bug causing the memory issue, so this PR is now complete. I'll close #8852 since that workaround won't be needed.

@astrofrog astrofrog modified the milestones: v2.0.15, v3.2.2 Jun 16, 2019
@astrofrog

Copy link
Copy Markdown
Member Author

By the way, it looks like as a result of how multiprocessing works in 'spawn' mode, the contents of the table are actually pickled, which means we lose the memory mapping. This is not something I've changed here, just what the behavior would have been, as implemented, if it hadn't been buggy. I've opened a new issue to remind us to check the performance in the 'spawn' mode: #8858

Comment thread astropy/io/ascii/cparser.pyx Outdated
# Since we already deallocated the tokenizer above, we should make sure we
# set self.tokenizer to NULL to avoid deallocating the tokenizer again
# inside __dealloc__.
self.tokenizer = NULL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This may be needed in the two except clauses above too ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed

@saimn

saimn commented Jun 16, 2019

Copy link
Copy Markdown
Contributor

Nice work! I think the changes makes sense to me, but this code is quite horrible so it's not easy to be sure :D.
Is it possible to test this, maybe with multiprocessing.set_start_method, or running the tests on windows (as you mentioned in #8851 (comment)) ?
About the fast_reader argument, this is bug present for all os, isn't it ?

@astrofrog

astrofrog commented Jun 17, 2019 •

Copy link
Copy Markdown
Member Author

@saimn - indeed it looks like things work properly on Windows now so I've removed the restrictions. Let's see if it works on AppVeyor too (edit: it does!). For the fast_reader bug in the CParser init, I don't think we really need a regression test because that class is never actually called directly by users, so it's never actually been called with no fast_reader argument, meaning the default has never been used, so it's not really a big issue.

@taldcroft

Copy link
Copy Markdown
Member

@astrofrog - this looks great, esp. the new support for windows!

Just to be clear, this does not change the start method in any way, it just makes things work with the default start method on all platforms. The issue #8858 should definitely be followed up to see if there is a big hit.

Although it is not clear if we can actually do anything about it. The multiprocessing docs say "set_start_method() should not be used more than once in the program.". At face value that implies the io.ascii fast reader would not be free to temporarily set to fork for a call to the fast reader on MacOS. It is certainly annoying that Apple has not addressed problems and Mac is basically getting the crippled multiprocessing support that Windows has.

@astrofrog

astrofrog commented Jun 17, 2019 •

Copy link
Copy Markdown
Member Author

@taldcroft - yes this doesn't change the start method, it just makes it work with the default on all platforms. In principle the Python docs do point out that you can temporarily set a context where you use a specific start method (see what I had done in #8852 as a workaround) but I think it'd be better to just make things work with the default, as done here.

@taldcroft taldcroft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have not reviewed the detailed cparser changes, but if tests pass then I'm satisfied. All the surrounding changes look good to me. Thanks for taking the dive to fix this long-standing limitation on Windows!

@astrofrog
astrofrog requested a review from saimn June 17, 2019 11:14
@pllim

pllim commented Jun 17, 2019

Copy link
Copy Markdown
Member

@saimn , do you want to add your seal of approval before merge?

Tests passed and there's one approval already. But extra approvals never hurt.

@saimn saimn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, and great to have this enabled on Windows !

@saimn
saimn merged commit 4bf8a91 into astropy:master Jun 17, 2019
bsipocz pushed a commit that referenced this pull request Jun 21, 2019
Fixes to io.ascii fast reader when used in multiprocessing 'spawn' mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants