-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 2 parameters to Start-ThreadJob: timeout seconds, priority #18999
Comments
Can you explain what you expect the timeout to do? What happens to code that is executing in the ThreadJob when the timeout expires? |
I suggest any timeout parameters should be consistent with Start-Sleep and priority consistent with ThreadPriority |
The timeout parameter is passed in when creating a thread. This should be the basic function of the basic library. Python has function, golang has. C #, powershell, does not have this function Have a way to function, on github? |
What is the effect the timeout supposed to have? As you say C# and PowerShell do not have this capability and PowerShell is built using C#. Neither does the underlying Win32 threading API. |
In theory you could use QueueUserAPC to inject a callback procedure which calls RaiseException, this would then cause structured exception handlers to unwind, but what actually happens is a complete trashing of the internal state of libraries which do not expect threads to suddenly start unwinding at unexpected points. Been there - done that. You then try replacing the RaiseException with a longjmp, this gives the same result as longjmp on Win32 also uses SEH. |
How dare you ask golang to cancel "context. WithTimeout"? Why does C # and PowerShell not provide background thread-timeout? |
Please open the issue in https://github.com/PowerShell/ThreadJob instead.
|
Unfortunately the Thread.Abort does not work
See also On replacing Thread.Abort() in .NET 6, .NET 5 and .NET Core |
@kasini3000 I think what you are looking for is CancellationTokenSource.CancelAfter Method |
@daxian-dbw, in general I wonder if it's better to report
This would simplify matters and help discoverability. |
@rhubarb-geek-nz, while all the technical background you provide and the questions you raise are interesting, note that we already do have thread (runspace) termination:
I don't know what mechanism is used to terminate threads / runspaces, but clearly the functionality is already available and raising concerns about how it works and whether variant functionality is called for would be a separate debate.
|
That is good news. My expectation would exposing the actual CancellationToken so that it can be used directly by cmdlets, eg StartSleepCommand.cs should sleep by waiting on the cancellation token rather than the ManualResetEvent. I notice that the WebCmdlet uses CancellationTokens, if this is same one used to abort the thread then cancelling a thread can very efficient. |
So to be clear, a CancellationToken based thread termination is cooperative and not preemptive and requires the target thread to still be responsive. |
i open new issue on threadjob: add PerTimeoutSecond to “ForEach-Object -Parallel” |
This issue has been marked as external and has not had any activity for 1 day. It has been be closed for housekeeping purposes. |
Summary of the new feature / enhancement
Add 2 parameters to Start-ThreadJob:
timeout seconds
priority
Proposed technical implementation details (optional)
A single asynchronous task has no timeout and no priority, It is very original.
The priority range is 1-9, and the default is 5,priority 1 will be executed first.
The text was updated successfully, but these errors were encountered: