Skip to content

Commit e36ff1e

Browse files
committed
Clean only current thread tmp files, add timestamp for multithreading
1 parent ba41090 commit e36ff1e

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

goose/Crawler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
limitations under the License.
2222
"""
2323
import os
24+
import glob
2425
from copy import deepcopy
2526
from goose.Article import Article
2627
from goose.utils import URLHelper
@@ -125,11 +126,10 @@ def getExtractor(self):
125126
return StandardContentExtractor(self.config)
126127

127128
def releaseResources(self, article):
128-
directory = self.config.localStoragePath
129-
for fname in os.listdir(directory):
130-
f = '%s/%s' % (self.config.localStoragePath, fname)
129+
path = '%s/%s_*' % (self.config.localStoragePath, article.linkhash)
130+
for fname in glob.glob(path):
131131
try:
132-
os.remove(f)
132+
os.remove(fname)
133133
except OSError:
134134
# TODO better log handeling
135135
pass

goose/utils/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
See the License for the specific language governing permissions and
2121
limitations under the License.
2222
"""
23+
import time
2324
import hashlib
2425
import re
2526
import os
@@ -92,7 +93,7 @@ def getCleanedUrl(self, urlToCrawl):
9293
finalUrl = urlToCrawl.replace('#!', '?_escaped_fragment_=') \
9394
if '#!' in urlToCrawl else urlToCrawl
9495

95-
linkhash = hashlib.md5(finalUrl).hexdigest()
96+
linkhash = '%s.%s' % (hashlib.md5(finalUrl).hexdigest(), time.time())
9697

9798
return ParsingCandidate(finalUrl, linkhash, finalUrl)
9899

0 commit comments

Comments
 (0)