async def test_spawn_context(self): with self.assertRaises(ValueError): amp.set_context("foo") async def inline(x): return x amp.set_context("spawn") with self.assertRaises(AttributeError): p = amp.Worker(target=inline, args=(1, ), name="test_inline") p.start() await p.join() p = amp.Worker(target=two, name="test_global") p.start() await p.join() values = list(range(10)) results = [await mapper(i) for i in values] async with amp.Pool(2) as pool: self.assertEqual(await pool.map(mapper, values), results) self.assertEqual(p.result, 2)
async def test_set_context(self, ssm_mock): amp.set_context() ssm_mock.assert_called_with(None) amp.set_context("foo") ssm_mock.assert_called_with("foo") ssm_mock.side_effect = Exception("fake exception") with self.assertRaisesRegex(Exception, "fake exception"): amp.set_context("whatever")
#!/usr/bin/env python3 # Note: This script runs theHarvester from platform import python_version import sys import asyncio if python_version()[0:3] < '3.7': print( '\033[93m[!] Make sure you have Python 3.7+ installed, quitting.\n\n \033[0m' ) sys.exit(1) from theHarvester import __main__ if __name__ == '__main__': platform = sys.platform if platform == 'win32': # Required or things will break if trying to take screenshots import multiprocessing multiprocessing.freeze_support() asyncio.DefaultEventLoopPolicy = asyncio.WindowsSelectorEventLoopPolicy else: import uvloop uvloop.install() if "linux" in platform: import aiomultiprocess # As we are not using Windows we can change the spawn method to fork for greater performance aiomultiprocess.set_context("fork") asyncio.run(__main__.entry_point())
def setUp(self): amp.set_context("fork")