<commit_before>import Pyro.core
import time
from Pyro.errors import TimeoutError

def approxEqual(x,y):
    return abs(x-y) < 0.1

# disable timeout globally 
Pyro.config.COMMTIMEOUT=None

obj=Pyro.core.Proxy("PYRONAME:example.timeout")
print "No timeout is configured. Calling delay with 2 seconds."
start=time.time()
result=obj.delay(2)
assert result=="slept 2 seconds"
duration=time.time()-start
assert approxEqual(duration,2), "expected 2 seconds duration"

# override timeout for this object
obj._pyroTimeout=1
print "Timeout set to 1 seconds. Calling delay with 2 seconds."
start=time.time()
try:
    result=obj.delay(2)
    print "!?should have raised TimeoutError!?"
except TimeoutError:
    print "Timeouterror! As expected!"
    duration=time.time()-start
    assert approxEqual(duration,1), "expected 1 seconds duration"

# set timeout globally
Pyro.config.COMMTIMEOUT=1

obj=Pyro.core.Proxy("PYRONAME:example.timeout")
print "COMMTIMEOUT is set globally. Calling delay with 2 seconds."
start=time.time()
try:
    result=obj.delay(2)
    print "!?should have raised TimeoutError!?"
except TimeoutError:
    print "Timeouterror! As expected!"
    duration=time.time()-start
    assert approxEqual(duration,1), "expected 1 seconds duration"

# override again for this object
obj._pyroTimeout=None
print "No timeout is configured. Calling delay with 3 seconds."
start=time.time()
result=obj.delay(3)
assert result=="slept 3 seconds"
duration=time.time()-start
assert approxEqual(duration,3), "expected 3 seconds duration"

print 
print "Trying to connect to the frozen daemon."
obj=Pyro.core.Proxy("PYRONAME:example.timeout.frozendaemon")
obj._pyroTimeout=1
print "Timeout set to 1 seconds. Trying to connect."
start=time.time()
try:
    result=obj.delay(5)
    print "!?should have raised TimeoutError!?"
except TimeoutError:    
    print "Timeouterror! As expected!"
    duration=time.time()-start
    assert approxEqual(duration,1), "expected 1 seconds duration"
print "Disabling timeout and trying to connect again. This may take forever now."
print "Feel free to abort with ctrl-c or ctrl-break."
obj._pyroTimeout=None
obj.delay(1)<commit_msg>ironpython fixes (timer is wacky in ipy)<commit_after>import Pyro.core
import time,sys
from Pyro.errors import TimeoutError


# NOTE: the timer in IronPython seems to be wacky.
# So we use wider margins for that, to check if the delays are ok.

def approxEqual(x,y):
    return abs(x-y) < 0.1

# disable timeout globally 
Pyro.config.COMMTIMEOUT=None

obj=Pyro.core.Proxy("PYRONAME:example.timeout")
print "No timeout is configured. Calling delay with 2 seconds."
start=time.time()
result=obj.delay(2)
assert result=="slept 2 seconds"
duration=time.time()-start
if sys.platform!="cli":
    assert approxEqual(duration,2), "expected 2 seconds duration"
else:
    assert 1.0<duration<3.0, "expected about 2 seconds duration"

# override timeout for this object
obj._pyroTimeout=1
print "Timeout set to 1 seconds. Calling delay with 2 seconds."
start=time.time()
try:
    result=obj.delay(2)
    print "!?should have raised TimeoutError!?"
except TimeoutError:
    print "Timeouterror! As expected!"
    duration=time.time()-start
    if sys.platform!="cli":
        assert approxEqual(duration,1), "expected 1 seconds duration"
    else:
        assert 0.9<duration<1.9, "expected about 1 second duration"

# set timeout globally
Pyro.config.COMMTIMEOUT=1

obj=Pyro.core.Proxy("PYRONAME:example.timeout")
print "COMMTIMEOUT is set globally. Calling delay with 2 seconds."
start=time.time()
try:
    result=obj.delay(2)
    print "!?should have raised TimeoutError!?"
except TimeoutError:
    print "Timeouterror! As expected!"
    duration=time.time()-start
    if sys.platform!="cli":
        assert approxEqual(duration,1), "expected 1 seconds duration"
    else:
        assert 0.9<duration<1.9, "expected about 1 second duration"

# override again for this object
obj._pyroTimeout=None
print "No timeout is configured. Calling delay with 3 seconds."
start=time.time()
result=obj.delay(3)
assert result=="slept 3 seconds"
duration=time.time()-start
if sys.platform!="cli":
    assert approxEqual(duration,3), "expected 3 seconds duration"
else:
    assert 2.5<duration<3.5, "expected about 3 second duration"

print 
print "Trying to connect to the frozen daemon."
obj=Pyro.core.Proxy("PYRONAME:example.timeout.frozendaemon")
obj._pyroTimeout=1
print "Timeout set to 1 seconds. Trying to connect."
start=time.time()
try:
    result=obj.delay(5)
    print "!?should have raised TimeoutError!?"
except TimeoutError:    
    print "Timeouterror! As expected!"
    duration=time.time()-start
    if sys.platform!="cli":
        assert approxEqual(duration,1), "expected 1 seconds duration"
    else:
        assert 0.9<duration<1.9, "expected about 1 second duration"

print "Disabling timeout and trying to connect again. This may take forever now."
print "Feel free to abort with ctrl-c or ctrl-break."
obj._pyroTimeout=None
obj.delay(1)
{'fraction_non_alphanumeric': 0.10955337472461446, 'fraction_numerical': 0.01662327258161426, 'mean_word_length': 4.687927107061504, 'pattern_counts': {'":': 5, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7528364', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1564, 'n_words': 496}