TimedPromise continues forever

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

TimedPromise continues forever

Steven Kelly

When a TimedPromise times out, the block it was running continues to run. How do you stop the block?

 

promise := [[1] repeat] timedPromiseFor: 5000 at: 47.

[[promise value] on: Protocols.PromiseExpiredError do: [:ex | ex return: nil]] fork

 

There doesn’t seem to be a path from the promise to the process running the block.

 

Steve

PS A hack to kill the process from the example above - (Processor processesAt: 47) do: #terminate


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: TimedPromise continues forever

Paul Baumann

Steve,

 

I'm guessing you'll find the block never got started. Refer to the attached discussion "A useful Promise" started 2010.04.14.

 

A ratchet semaphore is a direct way to address it and can use lower priority promises.

 

Paul Baumann

 

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kelly
Sent: Tuesday, January 25, 2011 13:57
To: VWNC List
Subject: [vwnc] TimedPromise continues forever

 

When a TimedPromise times out, the block it was running continues to run. How do you stop the block?

 

promise := [[1] repeat] timedPromiseFor: 5000 at: 47.

[[promise value] on: Protocols.PromiseExpiredError do: [:ex | ex return: nil]] fork

 

There doesn’t seem to be a path from the promise to the process running the block.

 

Steve

PS A hack to kill the process from the example above - (Processor processesAt: 47) do: #terminate



This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of IntercontinentalExchange, Inc. (ICE), its subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.

A Promise object seems useful to people who discover this gem, but the change in execution sequence prevents the most useful applications of this kind of object.
 
A promise forks a process. A forked process sits idle until the active process yields to other processes. This demonstrates the execution sequence:
 
| seq promise |
seq := OrderedCollection new.
seq add: 1.
promise := [ seq add: 2. Processor activeProcess yield. seq add: 4. seq ] promise.
seq add: 3.
promise value
 OrderedCollection (1 3 2 4)
Notice how 3 is before 2? This is just a side effect of the standard way that forked processes are scheduled.
 
Now consider when you might want to use a Promise. A very typical scenario is to do some server call and allow execution to continue while that call is being being done.
 
For example, this code attempts to start a GS query that is done in parallel with opening a window. Once the window is opened then the code waits for the query results to display them.
 
| gsResultPromise |
gsResultPromise := [ GBSM execute: 'Companies getAll' ] promise.
CompaniesView new
    open;
    displayCompanies: gsResultPromise value.
 
The thing is, because of process scheduling, the query doesn't actually start until after the active process yields to the query. In other words, all this trickery is no faster, and actually slows processing by adding the overhead of another process. You tend to find that this scenario is most common. You usually want to start work that you know will be delayed, allow work to continue on the main process, and then wait for results later. Unfortunately, the standard Promise does not behave this way. The standard Promise expects work to be delayed on the main process before allowing the promised work to get started.
 
Fortunately, there is a very simple solution...
 
BlockClosure>>deferable
 "Answer a Promise after work in the receiver block is suspended. -plb 2010.04.14"
 | prom ratchetSem |
 prom := Promise new.
 ratchetSem := Semaphore new.
 ([ratchetSem signal. self value] promiseBlock: prom) fork.
 ratchetSem wait.
 ^prom
 
This one forces the Promise to give the desired sequence:

| seq promise |
seq := OrderedCollection new.
seq add: 1.
promise := [ seq add: 2. Processor activeProcess yield. seq add: 4. seq ] deferable.
seq add: 3.
promise value
 OrderedCollection (1 2 3 4)
 
Obviously, the Promise.sync semaphore could have been reused to do the ratcheting without having to create a second semaphore. I showed it with a separate ratchet semaphore just to keep the example simple.
 
Paul Baumann 
 


This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of IntercontinentalExchange, Inc. (ICE), its subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

ATT00002.txt (186 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: TimedPromise continues forever

Steven Kelly

Paul,

 

The block gets started: I’m running this in a workspace so it gets sent #value immediately. The problem isn’t the starting, it’s the stopping :-).

 

I had my own homegrown code that used Delay and its semaphore, and terminated the block on timeout. However, it didn’t take care of passing exceptions from the child process to the parent, so I tried moving to TimedPromise. I was surprised that the default behavior wasn’t just to terminate the process at the timeout. Duration>>toFinish:orElse: and BlockClosure>>toolSafeIn:else: are similar to what I want in terms of terminating the runaway process, but don’t pass exceptions to the parent.

 

I suppose I need to make BlockClosure>>timedPromise… pass the new process to the promise, so that on timeout it at least has the information it needs.

 

Thanks for the pointer to your ratchet/deferable idea. I don’t need that myself, since I send value immediately anyway. As my promise blocks are at a lower priority, adding the ratchet just makes flow jump to the subprocess to run the #signal, which sends it back to the main process, and then my #value would send it back to the subprocess. If that analysis is right, I guess the ratchet is only useful if the subprocess is at the same priority?

 

Steve

 

From: Paul Baumann [mailto:[hidden email]]
Sent: 25. tammikuuta 2011 22:20
To: Steven Kelly; VWNC List
Subject: RE: TimedPromise continues forever

 

Steve,

 

I'm guessing you'll find the block never got started. Refer to the attached discussion "A useful Promise" started 2010.04.14.

 

A ratchet semaphore is a direct way to address it and can use lower priority promises.

 

Paul Baumann

 

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kelly
Sent: Tuesday, January 25, 2011 13:57
To: VWNC List
Subject: [vwnc] TimedPromise continues forever

 

When a TimedPromise times out, the block it was running continues to run. How do you stop the block?

 

promise := [[1] repeat] timedPromiseFor: 5000 at: 47.

[[promise value] on: Protocols.PromiseExpiredError do: [:ex | ex return: nil]] fork

 

There doesn’t seem to be a path from the promise to the process running the block.

 

Steve

PS A hack to kill the process from the example above - (Processor processesAt: 47) do: #terminate

 


This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of IntercontinentalExchange, Inc. (ICE), its subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: TimedPromise continues forever

Steven Kelly

I’ve published TimeLimitedPromise in the public store:

 

TimeLimitedPromise evaluates a block in a lower-priority subprocess, with a timeout. It has the ability to pass subprocess errors to the parent process, like Promise, and a timeout like TimedPromise. On timeout, it too raises PromiseExpiredError, but also first terminates the subprocess (any unwind blocks there are run, but you should still be careful that termination does not leave objects in a bad state).

 

Share and enjoy! (corrections welcome)

Steve

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kelly
Sent: 26. tammikuuta 2011 2:36
To: Paul Baumann; VWNC List
Subject: Re: [vwnc] TimedPromise continues forever

 

Paul,

 

The block gets started: I’m running this in a workspace so it gets sent #value immediately. The problem isn’t the starting, it’s the stopping :-).

 

I had my own homegrown code that used Delay and its semaphore, and terminated the block on timeout. However, it didn’t take care of passing exceptions from the child process to the parent, so I tried moving to TimedPromise. I was surprised that the default behavior wasn’t just to terminate the process at the timeout. Duration>>toFinish:orElse: and BlockClosure>>toolSafeIn:else: are similar to what I want in terms of terminating the runaway process, but don’t pass exceptions to the parent.

 

I suppose I need to make BlockClosure>>timedPromise… pass the new process to the promise, so that on timeout it at least has the information it needs.

 

Thanks for the pointer to your ratchet/deferable idea. I don’t need that myself, since I send value immediately anyway. As my promise blocks are at a lower priority, adding the ratchet just makes flow jump to the subprocess to run the #signal, which sends it back to the main process, and then my #value would send it back to the subprocess. If that analysis is right, I guess the ratchet is only useful if the subprocess is at the same priority?

 

Steve

 

From: Paul Baumann [mailto:[hidden email]]
Sent: 25. tammikuuta 2011 22:20
To: Steven Kelly; VWNC List
Subject: RE: TimedPromise continues forever

 

Steve,

 

I'm guessing you'll find the block never got started. Refer to the attached discussion "A useful Promise" started 2010.04.14.

 

A ratchet semaphore is a direct way to address it and can use lower priority promises.

 

Paul Baumann

 

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kelly
Sent: Tuesday, January 25, 2011 13:57
To: VWNC List
Subject: [vwnc] TimedPromise continues forever

 

When a TimedPromise times out, the block it was running continues to run. How do you stop the block?

 

promise := [[1] repeat] timedPromiseFor: 5000 at: 47.

[[promise value] on: Protocols.PromiseExpiredError do: [:ex | ex return: nil]] fork

 

There doesn’t seem to be a path from the promise to the process running the block.

 

Steve

PS A hack to kill the process from the example above - (Processor processesAt: 47) do: #terminate

 


This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of IntercontinentalExchange, Inc. (ICE), its subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: TimedPromise continues forever

Boris Popov, DeepCove Labs (SNN)

Steven,

 

How do you feel about the below patch to ensure that one can get the stack of promise’d process in the exception dump when the PromiseExpiredError is handled (via Process>>printStackOn: or RuntimeFullDumper>>dumpSuspendedProcesses)?

 

TimeLimitedPromise>>value

 

                delay wait.          "Wait for data arrival or alarm expiry."

                delay disable.

                sync signal.         "To allow multiple reads of the result"

                ^exception == nil

                                ifTrue:

                                                [hasValue

                                                                ifTrue: [value]

                                                                ifFalse:

                                                                                [process suspend.

                                                                                [self signalTimeout] ensure: [process terminate]]]

                                ifFalse:

                                                [exception

                                                                copyForReraise;

                                                                searchFrom: thisContext;

                                                                raise].

-Boris

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kelly
Sent: 26 January 2011 07:24
To: VWNC List
Subject: Re: [vwnc] TimedPromise continues forever

 

I’ve published TimeLimitedPromise in the public store:

 

TimeLimitedPromise evaluates a block in a lower-priority subprocess, with a timeout. It has the ability to pass subprocess errors to the parent process, like Promise, and a timeout like TimedPromise. On timeout, it too raises PromiseExpiredError, but also first terminates the subprocess (any unwind blocks there are run, but you should still be careful that termination does not leave objects in a bad state).

 

Share and enjoy! (corrections welcome)

Steve

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kelly
Sent: 26. tammikuuta 2011 2:36
To: Paul Baumann; VWNC List
Subject: Re: [vwnc] TimedPromise continues forever

 

Paul,

 

The block gets started: I’m running this in a workspace so it gets sent #value immediately. The problem isn’t the starting, it’s the stopping :-).

 

I had my own homegrown code that used Delay and its semaphore, and terminated the block on timeout. However, it didn’t take care of passing exceptions from the child process to the parent, so I tried moving to TimedPromise. I was surprised that the default behavior wasn’t just to terminate the process at the timeout. Duration>>toFinish:orElse: and BlockClosure>>toolSafeIn:else: are similar to what I want in terms of terminating the runaway process, but don’t pass exceptions to the parent.

 

I suppose I need to make BlockClosure>>timedPromise… pass the new process to the promise, so that on timeout it at least has the information it needs.

 

Thanks for the pointer to your ratchet/deferable idea. I don’t need that myself, since I send value immediately anyway. As my promise blocks are at a lower priority, adding the ratchet just makes flow jump to the subprocess to run the #signal, which sends it back to the main process, and then my #value would send it back to the subprocess. If that analysis is right, I guess the ratchet is only useful if the subprocess is at the same priority?

 

Steve

 

From: Paul Baumann [mailto:[hidden email]]
Sent: 25. tammikuuta 2011 22:20
To: Steven Kelly; VWNC List
Subject: RE: TimedPromise continues forever

 

Steve,

 

I'm guessing you'll find the block never got started. Refer to the attached discussion "A useful Promise" started 2010.04.14.

 

A ratchet semaphore is a direct way to address it and can use lower priority promises.

 

Paul Baumann

 

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kelly
Sent: Tuesday, January 25, 2011 13:57
To: VWNC List
Subject: [vwnc] TimedPromise continues forever

 

When a TimedPromise times out, the block it was running continues to run. How do you stop the block?

 

promise := [[1] repeat] timedPromiseFor: 5000 at: 47.

[[promise value] on: Protocols.PromiseExpiredError do: [:ex | ex return: nil]] fork

 

There doesn’t seem to be a path from the promise to the process running the block.

 

Steve

PS A hack to kill the process from the example above - (Processor processesAt: 47) do: #terminate

 


This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of IntercontinentalExchange, Inc. (ICE), its subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: TimedPromise continues forever

Boris Popov, DeepCove Labs (SNN)
In reply to this post by Steven Kelly

[([(2 ** 100) factorial] timeLimitedPromiseFor: 500

                at: Processor userSchedulingPriority - 1) value]

                                on: PromiseExpiredError

                                do: [:ex | ex return: (String streamContents: [:ws | ex parameter process printStackOn: ws])]

 

LargePositiveInteger(LargeInteger)>>*

LargePositiveInteger(Integer)>>factorial

optimized [] in [] in UndefinedObject>>unboundMethod

optimized [] in [] in [] in BlockClosure>>promiseBlock:

BlockClosure>>on:do:

optimized [] in [] in BlockClosure>>promiseBlock:

BlockClosure>>on:do:

optimized [] in BlockClosure>>promiseBlock:

BlockClosure>>on:do:

optimized [] in Process class>>forBlock:priority:

 

From: Boris Popov, DeepCove Labs
Sent: 26 May 2011 12:08
To: 'Steven Kelly'; VWNC List
Subject: RE: [vwnc] TimedPromise continues forever

 

Steven,

 

How do you feel about the below patch to ensure that one can get the stack of promise’d process in the exception dump when the PromiseExpiredError is handled (via Process>>printStackOn: or RuntimeFullDumper>>dumpSuspendedProcesses)?

 

TimeLimitedPromise>>value

 

                delay wait.          "Wait for data arrival or alarm expiry."

                delay disable.

                sync signal.         "To allow multiple reads of the result"

                ^exception == nil

                                ifTrue:

                                                [hasValue

                                                                ifTrue: [value]

                                                                ifFalse:

                                                                                [process suspend.

                                                                                [self signalTimeout] ensure: [process terminate]]]

                                ifFalse:

                                                [exception

                                                                copyForReraise;

                                                                searchFrom: thisContext;

                                                                raise].

-Boris

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kelly
Sent: 26 January 2011 07:24
To: VWNC List
Subject: Re: [vwnc] TimedPromise continues forever

 

I’ve published TimeLimitedPromise in the public store:

 

TimeLimitedPromise evaluates a block in a lower-priority subprocess, with a timeout. It has the ability to pass subprocess errors to the parent process, like Promise, and a timeout like TimedPromise. On timeout, it too raises PromiseExpiredError, but also first terminates the subprocess (any unwind blocks there are run, but you should still be careful that termination does not leave objects in a bad state).

 

Share and enjoy! (corrections welcome)

Steve

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kelly
Sent: 26. tammikuuta 2011 2:36
To: Paul Baumann; VWNC List
Subject: Re: [vwnc] TimedPromise continues forever

 

Paul,

 

The block gets started: I’m running this in a workspace so it gets sent #value immediately. The problem isn’t the starting, it’s the stopping :-).

 

I had my own homegrown code that used Delay and its semaphore, and terminated the block on timeout. However, it didn’t take care of passing exceptions from the child process to the parent, so I tried moving to TimedPromise. I was surprised that the default behavior wasn’t just to terminate the process at the timeout. Duration>>toFinish:orElse: and BlockClosure>>toolSafeIn:else: are similar to what I want in terms of terminating the runaway process, but don’t pass exceptions to the parent.

 

I suppose I need to make BlockClosure>>timedPromise… pass the new process to the promise, so that on timeout it at least has the information it needs.

 

Thanks for the pointer to your ratchet/deferable idea. I don’t need that myself, since I send value immediately anyway. As my promise blocks are at a lower priority, adding the ratchet just makes flow jump to the subprocess to run the #signal, which sends it back to the main process, and then my #value would send it back to the subprocess. If that analysis is right, I guess the ratchet is only useful if the subprocess is at the same priority?

 

Steve

 

From: Paul Baumann [mailto:[hidden email]]
Sent: 25. tammikuuta 2011 22:20
To: Steven Kelly; VWNC List
Subject: RE: TimedPromise continues forever

 

Steve,

 

I'm guessing you'll find the block never got started. Refer to the attached discussion "A useful Promise" started 2010.04.14.

 

A ratchet semaphore is a direct way to address it and can use lower priority promises.

 

Paul Baumann

 

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kelly
Sent: Tuesday, January 25, 2011 13:57
To: VWNC List
Subject: [vwnc] TimedPromise continues forever

 

When a TimedPromise times out, the block it was running continues to run. How do you stop the block?

 

promise := [[1] repeat] timedPromiseFor: 5000 at: 47.

[[promise value] on: Protocols.PromiseExpiredError do: [:ex | ex return: nil]] fork

 

There doesn’t seem to be a path from the promise to the process running the block.

 

Steve

PS A hack to kill the process from the example above - (Processor processesAt: 47) do: #terminate

 


This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of IntercontinentalExchange, Inc. (ICE), its subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: TimedPromise continues forever

Boris Popov, DeepCove Labs (SNN)
In reply to this post by Steven Kelly

Mind you, similar result could be obtained explicitly even when the process was terminated prior to signal, but the benefit of suspending and then terminating is that default RTP dumper will log suspended processes, but not terminated ones.

 

[([(2 ** 100) factorial] timeLimitedPromiseFor: 500

                at: Processor userSchedulingPriority - 1) value]

                                on: PromiseExpiredError

                                do: [:ex | ex return: (String streamContents: [:ws | ex parameter process printStackOn: ws])]

 

optimized [] in [] in Process>>terminate

LargePositiveInteger(LargeInteger)>>*

LargePositiveInteger(Integer)>>factorial

optimized [] in [] in UndefinedObject>>unboundMethod

optimized [] in [] in [] in BlockClosure>>promiseBlock:

BlockClosure>>on:do:

optimized [] in [] in BlockClosure>>promiseBlock:

BlockClosure>>on:do:

optimized [] in BlockClosure>>promiseBlock:

BlockClosure>>on:do:

optimized [] in Process class>>forBlock:priority:

 

From: Boris Popov, DeepCove Labs
Sent: 26 May 2011 13:08
To: 'Steven Kelly'; 'VWNC List'
Subject: RE: [vwnc] TimedPromise continues forever

 

[([(2 ** 100) factorial] timeLimitedPromiseFor: 500

                at: Processor userSchedulingPriority - 1) value]

                                on: PromiseExpiredError

                                do: [:ex | ex return: (String streamContents: [:ws | ex parameter process printStackOn: ws])]

 

LargePositiveInteger(LargeInteger)>>*

LargePositiveInteger(Integer)>>factorial

optimized [] in [] in UndefinedObject>>unboundMethod

optimized [] in [] in [] in BlockClosure>>promiseBlock:

BlockClosure>>on:do:

optimized [] in [] in BlockClosure>>promiseBlock:

BlockClosure>>on:do:

optimized [] in BlockClosure>>promiseBlock:

BlockClosure>>on:do:

optimized [] in Process class>>forBlock:priority:

 

From: Boris Popov, DeepCove Labs
Sent: 26 May 2011 12:08
To: 'Steven Kelly'; VWNC List
Subject: RE: [vwnc] TimedPromise continues forever

 

Steven,

 

How do you feel about the below patch to ensure that one can get the stack of promise’d process in the exception dump when the PromiseExpiredError is handled (via Process>>printStackOn: or RuntimeFullDumper>>dumpSuspendedProcesses)?

 

TimeLimitedPromise>>value

 

                delay wait.          "Wait for data arrival or alarm expiry."

                delay disable.

                sync signal.         "To allow multiple reads of the result"

                ^exception == nil

                                ifTrue:

                                                [hasValue

                                                                ifTrue: [value]

                                                                ifFalse:

                                                                                [process suspend.

                                                                                [self signalTimeout] ensure: [process terminate]]]

                                ifFalse:

                                                [exception

                                                                copyForReraise;

                                                                searchFrom: thisContext;

                                                                raise].

-Boris

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kelly
Sent: 26 January 2011 07:24
To: VWNC List
Subject: Re: [vwnc] TimedPromise continues forever

 

I’ve published TimeLimitedPromise in the public store:

 

TimeLimitedPromise evaluates a block in a lower-priority subprocess, with a timeout. It has the ability to pass subprocess errors to the parent process, like Promise, and a timeout like TimedPromise. On timeout, it too raises PromiseExpiredError, but also first terminates the subprocess (any unwind blocks there are run, but you should still be careful that termination does not leave objects in a bad state).

 

Share and enjoy! (corrections welcome)

Steve

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kelly
Sent: 26. tammikuuta 2011 2:36
To: Paul Baumann; VWNC List
Subject: Re: [vwnc] TimedPromise continues forever

 

Paul,

 

The block gets started: I’m running this in a workspace so it gets sent #value immediately. The problem isn’t the starting, it’s the stopping :-).

 

I had my own homegrown code that used Delay and its semaphore, and terminated the block on timeout. However, it didn’t take care of passing exceptions from the child process to the parent, so I tried moving to TimedPromise. I was surprised that the default behavior wasn’t just to terminate the process at the timeout. Duration>>toFinish:orElse: and BlockClosure>>toolSafeIn:else: are similar to what I want in terms of terminating the runaway process, but don’t pass exceptions to the parent.

 

I suppose I need to make BlockClosure>>timedPromise… pass the new process to the promise, so that on timeout it at least has the information it needs.

 

Thanks for the pointer to your ratchet/deferable idea. I don’t need that myself, since I send value immediately anyway. As my promise blocks are at a lower priority, adding the ratchet just makes flow jump to the subprocess to run the #signal, which sends it back to the main process, and then my #value would send it back to the subprocess. If that analysis is right, I guess the ratchet is only useful if the subprocess is at the same priority?

 

Steve

 

From: Paul Baumann [mailto:[hidden email]]
Sent: 25. tammikuuta 2011 22:20
To: Steven Kelly; VWNC List
Subject: RE: TimedPromise continues forever

 

Steve,

 

I'm guessing you'll find the block never got started. Refer to the attached discussion "A useful Promise" started 2010.04.14.

 

A ratchet semaphore is a direct way to address it and can use lower priority promises.

 

Paul Baumann

 

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kelly
Sent: Tuesday, January 25, 2011 13:57
To: VWNC List
Subject: [vwnc] TimedPromise continues forever

 

When a TimedPromise times out, the block it was running continues to run. How do you stop the block?

 

promise := [[1] repeat] timedPromiseFor: 5000 at: 47.

[[promise value] on: Protocols.PromiseExpiredError do: [:ex | ex return: nil]] fork

 

There doesn’t seem to be a path from the promise to the process running the block.

 

Steve

PS A hack to kill the process from the example above - (Processor processesAt: 47) do: #terminate

 


This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of IntercontinentalExchange, Inc. (ICE), its subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: TimedPromise continues forever

Steven Kelly
In reply to this post by Boris Popov, DeepCove Labs (SNN)

It sounds like a great idea to me! So if my process times out, it is just suspended, the timeout signaled and only then is the process terminated. I don't see that causing any problems for us.

 

I suppose it also opens up the question for a future improvement: that the response to the #signalTimeout might actually be to allow the process to continue.

 

Steve

 


From: Boris Popov, DeepCove Labs [mailto:[hidden email]]
Sent: Thu
26/05/2011 19:08
To:
Steven Kelly; VWNC List
Subject: RE: [vwnc] TimedPromise continues forever

Steven,

 

How do you feel about the below patch to ensure that one can get the stack of promise’d process in the exception dump when the PromiseExpiredError is handled (via Process>>printStackOn: or RuntimeFullDumper>>dumpSuspendedProcesses)?

 

TimeLimitedPromise>>value

 

                delay wait.          "Wait for data arrival or alarm expiry."

                delay disable.

                sync signal.         "To allow multiple reads of the result"

                ^exception == nil

                                ifTrue:

                                                [hasValue

                                                                ifTrue: [value]

                                                                ifFalse:

                                                                                [process suspend.

                                                                                [self signalTimeout] ensure: [process terminate]]]

                                ifFalse:

                                                [exception

                                                                copyForReraise;

                                                                searchFrom: thisContext;

                                                                raise].

-Boris

 

From: vwnc-bounces@cs.uiuc.edu [mailto:vwnc-bounces@cs.uiuc.edu] On Behalf Of Steven Kelly
Sent:
26 January 2011 07:24
To:
VWNC List
Subject: Re: [vwnc] TimedPromise continues forever

 

I’ve published TimeLimitedPromise in the public store:

 

TimeLimitedPromise evaluates a block in a lower-priority subprocess, with a timeout. It has the ability to pass subprocess errors to the parent process, like Promise, and a timeout like TimedPromise. On timeout, it too raises PromiseExpiredError, but also first terminates the subprocess (any unwind blocks there are run, but you should still be careful that termination does not leave objects in a bad state).

 

Share and enjoy! (corrections welcome)

Steve

 

From: vwnc-bounces@cs.uiuc.edu [mailto:vwnc-bounces@cs.uiuc.edu] On Behalf Of Steven Kelly
Sent: 26. tammikuuta 2011
2:36
To: Paul Baumann;
VWNC List
Subject: Re: [vwnc] TimedPromise continues forever

 

Paul,

 

The block gets started: I’m running this in a workspace so it gets sent #value immediately. The problem isn’t the starting, it’s the stopping :-).

 

I had my own homegrown code that used Delay and its semaphore, and terminated the block on timeout. However, it didn’t take care of passing exceptions from the child process to the parent, so I tried moving to TimedPromise. I was surprised that the default behavior wasn’t just to terminate the process at the timeout. Duration>>toFinish:orElse: and BlockClosure>>toolSafeIn:else: are similar to what I want in terms of terminating the runaway process, but don’t pass exceptions to the parent.

 

I suppose I need to make BlockClosure>>timedPromise… pass the new process to the promise, so that on timeout it at least has the information it needs.

 

Thanks for the pointer to your ratchet/deferable idea. I don’t need that myself, since I send value immediately anyway. As my promise blocks are at a lower priority, adding the ratchet just makes flow jump to the subprocess to run the #signal, which sends it back to the main process, and then my #value would send it back to the subprocess. If that analysis is right, I guess the ratchet is only useful if the subprocess is at the same priority?

 

Steve

 

From: Paul Baumann [mailto:[hidden email]]
Sent: 25. tammikuuta 2011
22:20
To:
Steven Kelly; VWNC List
Subject: RE: TimedPromise continues forever

 

Steve,

 

I'm guessing you'll find the block never got started. Refer to the attached discussion "A useful Promise" started 2010.04.14.

 

A ratchet semaphore is a direct way to address it and can use lower priority promises.

 

Paul Baumann

 

 

 

From: vwnc-bounces@cs.uiuc.edu [mailto:vwnc-bounces@cs.uiuc.edu] On Behalf Of Steven Kelly
Sent:
Tuesday, January 25, 2011 13:57
To:
VWNC List
Subject: [vwnc] TimedPromise continues forever

 

When a TimedPromise times out, the block it was running continues to run. How do you stop the block?

 

promise := [[1] repeat] timedPromiseFor: 5000 at: 47.

[[promise value] on: Protocols.PromiseExpiredError do: [:ex | ex return: nil]] fork

 

There doesn’t seem to be a path from the promise to the process running the block.

 

Steve

PS A hack to kill the process from the example above - (Processor processesAt: 47) do: #terminate

 


This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of IntercontinentalExchange, Inc. (ICE), its subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc