From a149a5ed3070bd52f57425d8b63b3a13c3b07b5f Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Fri, 22 Sep 2023 16:18:53 -0400 Subject: [PATCH] fix: Cleanup fd file descriptor, #494 --- scrapyd/runner.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/scrapyd/runner.py b/scrapyd/runner.py index 8712f12a..4e41b4a6 100644 --- a/scrapyd/runner.py +++ b/scrapyd/runner.py @@ -23,19 +23,18 @@ def project_environment(project): version, eggfile = eggstorage.get(project, eggversion) if eggfile: prefix = '%s-%s-' % (project, version) - fd, eggpath = tempfile.mkstemp(prefix=prefix, suffix='.egg') - lf = os.fdopen(fd, 'wb') - shutil.copyfileobj(eggfile, lf) - lf.close() - activate_egg(eggpath) + f = tempfile.NamedTemporaryFile(suffix='.egg', prefix=prefix, delete=False) + shutil.copyfileobj(eggfile, f) + f.close() + activate_egg(f.name) else: - eggpath = None + f = None try: assert 'scrapy.conf' not in sys.modules, "Scrapy settings already loaded" yield finally: - if eggpath: - os.remove(eggpath) + if f: + os.remove(f.name) def main():