[ome-devel] cli.invoke() closes session

Josh Moore josh at glencoesoftware.com
Thu Jan 25 17:11:21 GMT 2018


On Thu, Jan 25, 2018 at 5:51 PM, Eilidh Troup <e.troup at epcc.ed.ac.uk> wrote:
> Hi,

Hi Eilidh,


> I’m writing a script to transfer images from one OMERO to another, remote
> OMERO. When I call cli.invoke, it works, but then closes the session, so I
> have to create a new session for every call of cli.invoke. Is there a better
> way to do this?

Interesting. I was thinking that you needed a single line addition:

    sf = c.createSession(username,password)
    sf.detachOnDestroy()  # i.e. don't destroy my session
    cli = omero.cli.CLI()

but that's not working for me either, which I consider a bug. You can
workaround by using a lower-level command, onecmd, but you'll need to
take responsibility for the closing yourself:

try:
    # ....
    cli.onecmd(["import", "a.fake"])
    cli.onecmd(["import", "b.fake"])
finally:
    cli.close()


Regards,
~Josh


> Thanks,
> Eilidh
>
>
> import omero
> import omero.cli
> REMOTE_HOST = 'demo.openmicroscopy.org'
> REMOTE_PORT = 4064
> username = ""
> password = ""
> c = omero.client(host=REMOTE_HOST,
> port=REMOTE_PORT,args=["--Ice.Config=/dev/null", "--omero.debug=1"])
> c.createSession(username,password)
> cli = omero.cli.CLI()
> cli.loadplugins()
> cli.set_client(c)
> del os.environ["ICE_CONFIG"]
> file_loc =
> "/Users/eilidhtroup/OMERO/ManagedRepository/root_0/2017-12/05/20-55-11.910/antibiotic_plate.jpg"
> cli.invoke(["import", file_loc]) #works - remote
> cli.invoke(["import", file_loc]) # doesn't work - will import into local
> session if one exists.
> c.createSession(username,password)
> cli.set_client(c)
> cli.invoke(["import", file_loc]) #works again -remote.


More information about the ome-devel mailing list