Re: async
Norman Denayer <[email protected]> Thu, 26 Oct 2017 12:39:20 +0200
| Newsgroups | gmane.comp.python.db.cx-oracle |
|---|---|
| Message-ID | <[email protected]> |
--===============3121266996214389012== Content-Type: multipart/alternative; boundary="Apple-Mail=_F7D3E362-C94E-454B-BF60-6E43066B4482" --Apple-Mail=_F7D3E362-C94E-454B-BF60-6E43066B4482 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hello Walter, > (We can use cx_Oracle with these frameworks now, but during any calls = to the database the code can do nothing else except wait for the answer = from the database). =20 Actually, cx_Oracle use the macros Py_BEGIN_ALLOW_THREADS and = Py_END_ALLOW_THREADS to let other threads run during driver calls and = database work. So even without an async version of cx_Oracle, you may execute your = calls in a =E2=80=9Cconcurrent.futures.ThreadPoolExecutor=E2=80=9D Of course it=E2=80=99s not perfect but it allows async code still call = non-async code in a non-blocking way. =20 See: https://docs.python.org/3/library/asyncio-eventloop.html#executor = <https://docs.python.org/3/library/asyncio-eventloop.html#executor> = https://docs.python.org/3/library/concurrent.futures.html#concurrent.futur= es.ThreadPoolExecutor = <https://docs.python.org/3/library/concurrent.futures.html#concurrent.futu= res.ThreadPoolExecutor> Norman > On 26 Oct 2017, at 10:47, Walter D=C3=B6rwald <[email protected]> = wrote: >=20 > On 24 Oct 2017, at 19:57, Anthony Tuininga wrote: >=20 >> Hi Andrew, >>=20 >> Apologies for the delay in response. I had a busy month. :-) >>=20 >> There are no current plans to make cx_Oracle "compatible" with = asyncio, but >> that could change -- especially if you provided some indication of = what you >> meant by that request! It might be useful to create an issue on the >> cx_Oracle issues page providing some more details. That will give = others a >> chance to comment a well, since not everyone is on the mailing list. >=20 > I guess this would mean that for each method that talks to the = database there should be an async version, i.e. instead of >=20 > def print_foo(): > cursor.execute("select * from foo") > for row in cursor: > print(row) >=20 > we could do: >=20 > async def print_foo(): > await cursor.execute("select * from foo") > async for row in cursor: > print(row) >=20 > Then we could use cx_Oracle with other async frameworks (aiohttp, = sanic and probably Tornado and Twisted and a bunch others) and take = advantage of cx_Oracle's new async features. >=20 > (We can use cx_Oracle with these frameworks now, but during any calls = to the database the code can do nothing else except wait for the answer = from the database). >=20 > Details for async/await are in PEP 492 at = https://www.python.org/dev/peps/pep-0492/ >=20 >> Anthony >>=20 >> On Mon, Sep 25, 2017 at 10:22 PM, Andrew Zyman <[email protected]> = wrote: >>=20 >>> Hello, >>> wonder if there are any plans to make the module "compatible" with >>> asyncio ? >>> Thank you >>> AZ >=20 > Servus, > Walter >=20 > = --------------------------------------------------------------------------= ---- > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > cx-oracle-users mailing list > cx-oracle-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users --Apple-Mail=_F7D3E362-C94E-454B-BF60-6E43066B4482 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 <html><head><meta http-equiv=3D"Content-Type" content=3D"text/html = charset=3Dutf-8"></head><body style=3D"word-wrap: break-word; = -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" = class=3D"">Hello Walter,<div class=3D""><br class=3D""></div><blockquote = type=3D"cite" class=3D"">(We can use cx_Oracle with these frameworks = now, but during any calls to the database the code can do nothing else = except wait for the answer from the database).<br = class=3D""></blockquote><div class=3D""> </div><div = class=3D"">Actually, cx_Oracle use the macros <span style=3D"color: = rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, 'Liberation = Mono', Menlo, Courier, monospace; orphans: 2; white-space: pre; widows: = 2; background-color: rgb(255, 255, 255);" = class=3D"">Py_BEGIN_ALLOW_THREADS and </span><span style=3D"color: = rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, 'Liberation = Mono', Menlo, Courier, monospace; orphans: 2; white-space: pre; widows: = 2; background-color: rgb(255, 255, 255);" class=3D"">Py_END_ALLOW_THREADS = t</span><span style=3D"color: rgb(36, 41, 46); orphans: 2; white-space: = pre; widows: 2; background-color: rgb(255, 255, 255);" class=3D"">o let = other threads run during driver calls and database = work.</span></div><div style=3D"orphans: auto; widows: auto;" = class=3D""><span style=3D"color: rgb(36, 41, 46); orphans: 2; = white-space: pre; widows: 2; background-color: rgb(255, 255, 255);" = class=3D"">So even without an async version of cx_Oracle, you may = execute your calls in a </span><font color=3D"#24292e" class=3D""><span = style=3D"white-space: pre;" class=3D"">=E2=80=9C<u = class=3D"">concurrent.futures.ThreadPoolExecutor</u>=E2=80=9D</span> = </font></div><div class=3D""><font color=3D"#24292e" class=3D""><span = style=3D"white-space: pre;" class=3D""><br = class=3D""></span></font></div><div class=3D""><font color=3D"#24292e" = class=3D""><span style=3D"white-space: pre;" class=3D"">Of course it=E2=80= =99s not perfect but it allows async code still call non-async code in a = non-blocking way.</span></font></div><div class=3D""><font = color=3D"#24292e" class=3D""><span style=3D"white-space: pre;" class=3D"">= </span></font></div><div class=3D""><font color=3D"#24292e" = face=3D"SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, = monospace" class=3D""><span style=3D"white-space: pre;" = class=3D"">See:</span></font></div><div class=3D""><span style=3D"orphans:= 2; widows: 2; background-color: rgb(255, 255, 255); white-space: pre;" = class=3D""><font color=3D"#24292e" face=3D"SFMono-Regular, Consolas, = Liberation Mono, Menlo, Courier, monospace" class=3D""><a = href=3D"https://docs.python.org/3/library/asyncio-eventloop.html#executor"= = class=3D"">https://docs.python.org/3/library/asyncio-eventloop.html#execut= or</a></font></span></div><div class=3D""><span style=3D"orphans: 2; = widows: 2; background-color: rgb(255, 255, 255); white-space: pre;" = class=3D""><font color=3D"#24292e" face=3D"SFMono-Regular, Consolas, = Liberation Mono, Menlo, Courier, monospace" class=3D""><a = href=3D"https://docs.python.org/3/library/concurrent.futures.html#concurre= nt.futures.ThreadPoolExecutor" = class=3D"">https://docs.python.org/3/library/concurrent.futures.html#concu= rrent.futures.ThreadPoolExecutor</a></font></span></div><div = class=3D""><span style=3D"orphans: 2; widows: 2; background-color: = rgb(255, 255, 255); white-space: pre;" class=3D""><font color=3D"#24292e" = face=3D"SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, = monospace" class=3D""><br class=3D""></font></span></div><div = class=3D""><span style=3D"orphans: 2; widows: 2; background-color: = rgb(255, 255, 255); white-space: pre;" class=3D""><font color=3D"#24292e" = face=3D"SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, = monospace" class=3D"">Norman</font></span></div><div class=3D""><br = class=3D""><div><blockquote type=3D"cite" class=3D""><div class=3D"">On = 26 Oct 2017, at 10:47, Walter D=C3=B6rwald <<a = href=3D"mailto:[email protected]" = class=3D"">[email protected]</a>> wrote:</div><br = class=3D"Apple-interchange-newline"><div class=3D""><div class=3D"">On = 24 Oct 2017, at 19:57, Anthony Tuininga wrote:<br class=3D""><br = class=3D""><blockquote type=3D"cite" class=3D"">Hi Andrew,<br = class=3D""><br class=3D"">Apologies for the delay in response. I had a = busy month. :-)<br class=3D""><br class=3D"">There are no current plans = to make cx_Oracle "compatible" with asyncio, but<br class=3D"">that = could change -- especially if you provided some indication of what = you<br class=3D"">meant by that request! It might be useful to create an = issue on the<br class=3D"">cx_Oracle issues page providing some more = details. That will give others a<br class=3D"">chance to comment a well, = since not everyone is on the mailing list.<br class=3D""></blockquote><br = class=3D"">I guess this would mean that for each method that talks to = the database there should be an async version, i.e. instead of<br = class=3D""><br class=3D""> def print_foo():<br = class=3D""> = cursor.execute("select * from = foo")<br class=3D""> for row = in cursor:<br class=3D""><span class=3D"Apple-tab-span" = style=3D"white-space:pre"> </span> = print(row)<br class=3D""><br = class=3D"">we could do:<br class=3D""><br class=3D""> = async def print_foo():<br class=3D""> = await cursor.execute("select * = from foo")<br class=3D""> = async for row in cursor:<br = class=3D""> = print(ro= w)<br class=3D""><br class=3D"">Then we could use cx_Oracle with other = async frameworks (aiohttp, sanic and probably Tornado and Twisted and a = bunch others) and take advantage of cx_Oracle's new async features.<br = class=3D""><br class=3D"">(We can use cx_Oracle with these frameworks = now, but during any calls to the database the code can do nothing else = except wait for the answer from the database).<br class=3D""><br = class=3D"">Details for async/await are in PEP 492 at <a = href=3D"https://www.python.org/dev/peps/pep-0492/" = class=3D"">https://www.python.org/dev/peps/pep-0492/</a><br class=3D""><br= class=3D""><blockquote type=3D"cite" class=3D"">Anthony<br class=3D""><br= class=3D"">On Mon, Sep 25, 2017 at 10:22 PM, Andrew Zyman <<a = href=3D"mailto:[email protected]" class=3D"">[email protected]</a>> = wrote:<br class=3D""><br class=3D""><blockquote type=3D"cite" = class=3D"">Hello,<br class=3D""> wonder if there are any plans to make = the module "compatible" with<br class=3D"">asyncio ?<br class=3D"">Thank = you<br class=3D"">AZ<br class=3D""></blockquote></blockquote><br = class=3D"">Servus,<br class=3D""> Walter<br class=3D""><br = class=3D"">---------------------------------------------------------------= ---------------<br class=3D"">Check out the vibrant tech community on = one of the world's most<br class=3D"">engaging tech sites, <a = href=3D"http://Slashdot.org" class=3D"">Slashdot.org</a>! <a = href=3D"http://sdm.link/slashdot" = class=3D"">http://sdm.link/slashdot</a><br = class=3D"">_______________________________________________<br = class=3D"">cx-oracle-users mailing list<br class=3D""><a = href=3D"mailto:cx-oracle-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org" = class=3D"">cx-oracle-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org</a><br = class=3D"">https://lists.sourceforge.net/lists/listinfo/cx-oracle-users<br= class=3D""></div></div></blockquote></div><br = class=3D""></div></body></html>= --Apple-Mail=_F7D3E362-C94E-454B-BF60-6E43066B4482-- --===============3121266996214389012== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot --===============3121266996214389012== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ cx-oracle-users mailing list cx-oracle-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/cx-oracle-users --===============3121266996214389012==--