Skip to content

Commit

Permalink
fix: Cleanup fd file descriptor, #494
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Sep 22, 2023
1 parent 67a0d21 commit a149a5e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions scrapyd/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit a149a5e

Please sign in to comment.