-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #287 from datosgobar/282-validar-borken-url-parale…
…lizando 282 validar borken url paralelizando
- Loading branch information
Showing
8 changed files
with
134 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from multiprocessing.pool import ThreadPool | ||
|
||
|
||
def apply_threading(l, function, cant_threads): | ||
if cant_threads == 1: | ||
return [function(x) for x in l] | ||
pool = ThreadPool(processes=cant_threads) | ||
results = pool.map(function, l) | ||
pool.close() | ||
pool.join() | ||
return results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
from unittest import TestCase | ||
|
||
|
||
from pydatajson.threading_helper import apply_threading | ||
|
||
|
||
class ThreadingTests(TestCase): | ||
|
||
def test_threading(self): | ||
elements = [1, 2, 3, 4] | ||
|
||
def function(x): | ||
return x ** 2 | ||
|
||
result = apply_threading(elements, function, 3) | ||
|
||
self.assertEqual(result, [1, 4, 9, 16]) | ||
|
||
def test_broken_function(self): | ||
elements = [1, 2, 3, 0] | ||
|
||
def divide(x): | ||
return 6/x | ||
with self.assertRaises(ZeroDivisionError): # Es "sincrónico"! | ||
apply_threading(elements, divide, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters