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

Close requests.Socket in RemoteScheduler before exiting (#3173) #3175

Merged
merged 2 commits into from Jun 23, 2022

Conversation

starhel
Copy link
Contributor

@starhel starhel commented Jun 10, 2022

Description

If using luigi.build and sys.exit, ResourceWarning on unclosed socket is raised. As it can be easily fixed, I've added requests.Session.close call before exiting.

Motivation and Context

Fixes #3173

Have you tested this? If so, how?

I've tested it using code below under py38. Adding solid unit/integration test requires running remote scheduler and I will need guidance if one is needed.

import sys
from time import sleep

import luigi


class Task(luigi.Task):
    p = luigi.IntParameter()

    def run(self):
        with self.output().open('w') as f:
            sleep(1)
            f.write(str(self.p))

    def output(self):
        return luigi.LocalTarget(f'file_{self.p}.txt')


if __name__ == '__main__':
    sys.exit(0 if luigi.build([Task(p=2)], local_scheduler=False) else 1)

@starhel starhel requested review from dlstadther and a team as code owners June 10, 2022 17:54
Copy link
Collaborator

@dlstadther dlstadther left a comment

Choose a reason for hiding this comment

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

lgtm! Thanks!

@dlstadther dlstadther merged commit c135664 into spotify:master Jun 23, 2022
@starhel starhel deleted the 3173_close_socket branch August 19, 2022 16:46
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.

Unclosed socket from luigi.rpc module
2 participants