Skip to content

Commit

Permalink
Do not create default pool as it blocks process termination.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Apr 18, 2023
1 parent 10ba9a4 commit a97ebb9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
8 changes: 3 additions & 5 deletions asyncbg/__init__.py
Expand Up @@ -33,10 +33,7 @@ async def call(self, callback, *args, **kwargs):
return await asyncio.wrap_future(self.submit(callback, *args, **kwargs))


_DEFAULT_POOL = ProcessPoolExecutor()


def call(callback, *args, **kwargs):
async def call(callback, *args, **kwargs):
"""Coroutine calling given callback with given arguments in
another process.
Expand All @@ -55,4 +52,5 @@ def call(callback, *args, **kwargs):
"""

return _DEFAULT_POOL.call(callback, *args, **kwargs)
with ProcessPoolExecutor() as pool:
return await pool.call(callback, *args, **kwargs)
2 changes: 1 addition & 1 deletion asyncbg/version.py
@@ -1 +1 @@
__version__ = '0.8.0'
__version__ = '0.9.0'
13 changes: 13 additions & 0 deletions tests/test_asyncbg.py
@@ -1,5 +1,6 @@
import asyncio
import unittest
import multiprocessing

import asyncbg

Expand All @@ -16,6 +17,10 @@ def pool_work(value_1, value_2=1):
return value_1 * value_2


def call_other_process():
asyncio.run(asyncbg.call(print, None))


class AsyncbgTest(unittest.TestCase):

def test_call_result(self):
Expand All @@ -40,6 +45,14 @@ async def pool(self):
for i in range(10):
self.assertEqual(await pool.call(pool_work, i, value_2=i), i * i)

def test_call_other_process(self):
asyncio.run(self.call_other_process())

async def call_other_process(self):
proc = multiprocessing.Process(target=call_other_process)
proc.start()
proc.join()


if __name__ == '__main__':
unittest.main()

0 comments on commit a97ebb9

Please sign in to comment.