[Tutor] Is context manager the answer to synchronous function calls?

John Wong gokoproject at gmail.com
Wed Sep 16 10:34:19 EDT 2015


On Wed, Sep 16, 2015 at 7:54 AM, Mark Lawrence <breamoreboy at yahoo.co.uk>
wrote:

>
> Assuming your (Alan's) guess is correct, and I certainly agree it's
> plausible, I suspect this might be better asked on the main Python mailing
> list, I don't see this as tutor material.
>
> Sorry first time posting to tutor / general list. Usually on TIP list. As
per Mark's recommendation, now posting to python-list at python.org.
<python-list at python.org>

On Wed, Sep 16, 2015 at 6:56 AM, Alan Gauld <alan.gauld at btinternet.com>
wrote:

>
> You don't actually specify but I'm guessing VM
> means Virtual Machine? Is it a specific type
> of VM? eg VMWare/VirtualBox or somesuch, or is
> it more of a sandbox environment like virtualenv?
> That might help us understand the restrictions better.


In my case my underlying functions will use boto (Amazon Web Service's
Python SDK) but I thought to abstract the details away from posting because
as you know I want to simply return an object. But yes, boto will simply
return the call with a response object. For example, to create an RDS
database, the call is returned and I will to query for the status of the
database before I can perform further actions to the instance such as
changing password (which is covered in the modify_vm function call). But
creating VM such as EC2 has an equal synchronous nature.

I would be tempted to use an asynchronous approach with a
> when_ready() function that takes my function as an input
> parameter. You could then run the when_ready in a thread
> or, I suspect, utilize the asyncio or asyncore modules,
> although I haven't tried using them for this kind of
> thing myself.
>
The bottom line is you need to wait for the status to
> change. How you do that wait is up to you but you can
> make it more readable for the user. The easier it is for
> the user the harder it will be for you.
>
>
Sounds like to make it readable and user friendly, also to have separation
of concern, I almost am locked into implementing in OOP style. Imperative
seems to be okay but lack the "shininess."

 Thank you.

John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150916/68593014/attachment.html>


More information about the Python-list mailing list