[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [HTCondor-users] list(ExprTree) infinite loop



Hi Brian,

Thanks for the bug report!

It's a really interesting one; I'm not sure of the way to solve this.  Stumped the expert!

Basically, when you call list(classad.ExprTree("2+2")), the python starts putting together a list.  It notes that ExprTree provides "__getitem__" and begins building a list like this:

[classad.ExprTree("2+2")[0], classad.ExprTree("2+2")[1], ... ]

I think it continues to do that until an IndexError is thrown.

So, what's the problem here?

The expression tree is lazily-evaluated.  classad.ExprTree("2+2")[0] is equivalent to "(2+2)[0]".  This is a perfectly valid expression - which is obviously going to end in error when you evaluate it.  However, without evaluating it, we've got no way to know it'll end in tears.

Any suggestions from the list on how the semantics should work here?

Brian

> On Nov 18, 2014, at 9:52 AM, Brian Candler <b.candler@xxxxxxxxx> wrote:
> 
> Condor 8.2.4 under ubuntu
> 
> Minor bug report: the python API can be made to hang if you call list() on certain forms of ExprTree. Reproducer:
> 
> >>> import classad
> >>> classad.ExprTree('{ "foo" }')
> { "foo" }
> >>> list(classad.ExprTree('{ "foo" }'))
> ['foo']
> >>> classad.ExprTree('2+2')
> 2 + 2
> >>> list(classad.ExprTree('2+2'))
> [ HANGS HERE, EVENTUALLY CRASHES OOM ]
> 
> Or:
> 
> for i in classad.ExprTree('2+2'):
>    print i
> [ INFINITE LOOP, EVENTUALLY CRASHES OOM ]
> 
> 
> Reason I'm doing this: I want to parse the node.status file, which is in new ClassAd format, and convert it to JSON.
> http://research.cs.wisc.edu/htcondor/manual/current/2_10DAGMan_Applications.html#sec:DAG-node-status
> 
> The following code does more or less what I want:
> 
> ad = classad.parse(f)
> jad = dict(ad)
> 
> except the DagFiles entry is an ExprTree. It can be forced to a str(), but that loses the structure of the value. Using list() here does what I want, but I was surprised to see it break for other ExprTree values.
> 
> It seems maybe classad.ExprTree.eval() is the way to go.
> 
> Regards,
> 
> Brian.
> 
> _______________________________________________
> HTCondor-users mailing list
> To unsubscribe, send a message to htcondor-users-request@xxxxxxxxxxx with a
> subject: Unsubscribe
> You can also unsubscribe by visiting
> https://lists.cs.wisc.edu/mailman/listinfo/htcondor-users
> 
> The archives can be found at:
> https://lists.cs.wisc.edu/archive/htcondor-users/