Skip to content

Commit

Permalink
remote iterators no longer perform unnecessary close calls
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Mar 11, 2017
1 parent 0f0945a commit b7dbc9f
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 22 deletions.
13 changes: 12 additions & 1 deletion dotnet/Pyrolite.TestPyroEcho/TestStreaming.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* part of Pyrolite, by Irmen de Jong (irmen@razorvine.net) */

using System;
using System.Collections;
using Razorvine.Pyro;

namespace Pyrolite.TestPyroEcho
Expand Down Expand Up @@ -54,12 +55,22 @@ public void Run() {
Console.WriteLine("SLOW GENERATOR:");
using(result = p.slow_generator())
{
Console.WriteLine(result);
foreach(int i in result)
{
Console.WriteLine(i);
}
}

Console.WriteLine("STOPPING GENERATOR HALFWAY:");
using(result=p.generator())
{
IEnumerator enumerator = result.GetEnumerator();
enumerator.MoveNext();
Console.WriteLine(enumerator.Current);
enumerator.MoveNext();
Console.WriteLine(enumerator.Current);
Console.WriteLine("...stopping...");
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions dotnet/Pyrolite/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion ("4.18.0.*")]
[assembly: AssemblyFileVersion("4.18.0.0")]
[assembly: AssemblyVersion ("4.19.0.*")]
[assembly: AssemblyFileVersion("4.19.0.0")]
2 changes: 1 addition & 1 deletion dotnet/Pyrolite/Pyro/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum SerializerType {
public static bool METADATA = true;

public const int PROTOCOL_VERSION = 48; // Pyro 4.38+
public const string PYROLITE_VERSION="4.18";
public const string PYROLITE_VERSION="4.19";

public const string DAEMON_NAME = "Pyro.Daemon";
}
Expand Down
8 changes: 6 additions & 2 deletions dotnet/Pyrolite/Pyro/PyroProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@ public StreamResultIterator(string streamId, PyroProxy proxy)

public IEnumerator GetEnumerator()
{
if(this.proxy==null)
yield break;

while(true) {
if(this.proxy.sock ==null) {
throw new PyroException("the proxy for this stream result has been closed");
Expand All @@ -485,10 +488,11 @@ public IEnumerator GetEnumerator()
value = this.proxy.internal_call("get_next_stream_item", Config.DAEMON_NAME, 0, false, new [] {this.streamId});
} catch (PyroException x) {
if(stopIterationExceptions.Contains(x.PythonExceptionType)) {
// iterator ended normally.
this.Dispose();
// iterator ended normally. no need to call close_stream, server will have closed the stream on its side already.
this.proxy = null;
yield break;
}
Dispose();
throw;
}
yield return value;
Expand Down
8 changes: 4 additions & 4 deletions dotnet/Pyrolite/Pyrolite.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Razorvine.Pyrolite</id>
<version>4.18.0.0</version>
<version>4.19.0.0</version>
<title>Razorvine.Pyrolite</title>
<authors>Irmen de Jong</authors>
<owners>Irmen de Jong</owners>
Expand All @@ -14,13 +14,13 @@ Also includes Pickle/Unpickle.
More info about Pyro: http://pythonhosted.org/Pyro4/</description>
<summary>Pyro (Python Remote Objects) client library</summary>
<releaseNotes>
Require Serpent library 1.17 because of critical fixes regarding serialization and parsing of strings.
Now recognises classes with [Serializable] or [DataContract] attributes an serializes their fields accordingly.
Remote iterators no longer perform unnecessary close calls when their iteration has completed.
Razorvine.Serpent library dependency updated to 1.18.
</releaseNotes>
<copyright>Copyright 2015, 2016, 2017</copyright>
<tags>pyro python rpc remote-objects</tags>
<dependencies>
<dependency id="Razorvine.Serpent" version="1.17" />
<dependency id="Razorvine.Serpent" version="1.18" />
</dependencies>
</metadata>
<files>
Expand Down
Binary file modified dotnet/lib/Razorvine.Serpent.dll
Binary file not shown.
7 changes: 4 additions & 3 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<dependency>
<groupId>net.razorvine</groupId>
<artifactId>serpent</artifactId>
<version>1.17</version>
<version>1.18</version>
</dependency>
</dependencies>
<scm>
Expand Down Expand Up @@ -94,7 +94,8 @@

Pyrolite only implements part of the client side Pyro library, hence its name 'lite'... But because Pyrolite has no dependencies, it is a much lighter way to use Pyro from Java/.NET than a solution with jython+pyro or IronPython+Pyro would provide. So if you don't need Pyro's full feature set, and don't require your Java/.NET code to host Pyro objects itself, Pyrolite may be a good choice to connect java or .NET and python.

Version 4.18 changes:
Require Serpent library 1.17 because of critical fixes regarding serialization and parsing of strings.
Version 4.19 changes:
Remote iterators no longer perform unnecessary close calls when their iteration has completed.
Require Serpent library 1.18.
</description>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Object constructors and other utility classes for the pickle package.
*
* @author Irmen de Jong (irmen@razorvine.net)
* @version 4.18
* @version 4.19
* @see net.razorvine.pickle
*/
package net.razorvine.pickle.objects;
2 changes: 1 addition & 1 deletion java/src/main/java/net/razorvine/pickle/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* functionality.
*
* @author Irmen de Jong (irmen@razorvine.net)
* @version 4.18
* @version 4.19
*/
package net.razorvine.pickle;

2 changes: 1 addition & 1 deletion java/src/main/java/net/razorvine/pyro/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public final class Config implements Serializable {
public static int NS_BCPORT = 9091;

public final static int PROTOCOL_VERSION = 48; // Pyro 4.38 and later
public final static String PYROLITE_VERSION = "4.18";
public final static String PYROLITE_VERSION = "4.19";

public enum SerializerType {
pickle,
Expand Down
14 changes: 10 additions & 4 deletions java/src/main/java/net/razorvine/pyro/PyroProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,10 @@ public StreamResultIterable(String streamId, PyroProxy proxy)

@Override
public Iterator<Object> iterator() {
return new StreamResultIterator(this.streamId, this.proxy);
return new StreamResultIterator<Object>(this.streamId, this.proxy);
}

private class StreamResultIterator implements Iterator<Object>
public class StreamResultIterator<T> implements Iterator<Object>
{
private String streamId;
private PyroProxy proxy;
Expand Down Expand Up @@ -516,6 +516,11 @@ public boolean hasNext() {
@Override
public Object next()
{
if(proxy==null) {
exhausted = true;
throw new NoSuchElementException("no proxy connected anymore");
}

if(hasNext()) {
getRemoteNext = true;
return nextValue;
Expand All @@ -533,12 +538,13 @@ protected Object get_next()
try {
value = proxy.internal_call("get_next_stream_item", Config.DAEMON_NAME, 0, false, streamId);
} catch (PyroException x) {
close();
exhausted=true;
if(stopIterationExceptions.contains(x.pythonExceptionType)) {
// iterator ended normally.
// iterator ended normally. no need to call close_stream, server will have closed the stream on its side already.
proxy = null;
return null;
}
close();
throw x;
} catch (IOException x) {
close();
Expand Down
2 changes: 1 addition & 1 deletion java/src/main/java/net/razorvine/pyro/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Note that Pyrolite only supports Pyro4.
*
* @author Irmen de Jong (irmen@razorvine.net)
* @version 4.18
* @version 4.19
* @see net.razorvine.pickle
*/
package net.razorvine.pyro;
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static PyroSerializer getFor(Config.SerializerType type)
// try loading it
try {
serpentSerializer = new SerpentSerializer();
final String requiredSerpentVersion = "1.17";
final String requiredSerpentVersion = "1.18";
if(compareLibraryVersions(net.razorvine.serpent.LibraryVersion.VERSION, requiredSerpentVersion) < 0)
{
throw new java.lang.RuntimeException("serpent version "+requiredSerpentVersion+" (or newer) is required");
Expand Down
15 changes: 15 additions & 0 deletions java/src/test/java/net/razorvine/examples/StreamingExample.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package net.razorvine.examples;

import java.io.IOException;
import java.util.Iterator;
import java.util.Scanner;

import net.razorvine.pyro.Config;
import net.razorvine.pyro.PyroProxy;
import net.razorvine.pyro.PyroProxy.StreamResultIterable;
import net.razorvine.pyro.PyroURI;

/**
Expand Down Expand Up @@ -60,6 +62,19 @@ public static void main(String[] args) throws IOException {
for(int i: iter) {
System.out.println(i);
}

System.out.println("STOPPING GENERATOR HALFWAY:");
result = p.call("slow_generator");
Iterable<Integer> iterable = (Iterable<Integer>) result;
Iterator<Integer> iterator = iterable.iterator();
System.out.println(iterator.next());
System.out.println(iterator.next());
System.out.println("...stopping...");
// the call below is a rather nasty way to force the iterator to close before reaching the end
((StreamResultIterable.StreamResultIterator) iterator).close();

iterable = null;
iterator = null;

// tidy up:
p.close();
Expand Down

0 comments on commit b7dbc9f

Please sign in to comment.