task

asyncio and coroutines vs task queues

倖福魔咒の 提交于 2021-02-06 07:55:09
问题 I've been reading about asyncio module in python 3, and more broadly about coroutines in python, and I can't get what makes asyncio such a great tool. I have the feeling that all you can do with coroutines, you can do it better by using task queues based of the multiprocessing module (celery for example). Are there usecases where coroutines are better than task queues ? 回答1: Not a proper answer, but a list of hints that could not fit into a comment: You are mentioning the multiprocessing

DeadLock on task.Wait() with Task which edit UI

寵の児 提交于 2021-02-05 10:40:39
问题 I'm trying to find some solutions to my problem here, but with no result (or I just do not get them right) so if anyone could help / explain i will be really gratefull. I'm just developing a tool for system administrators using Win Form and now I need to create a continuous ping on the selected machine which is running on the background. There is an indicator for Online status on UI which I need to edit with background ping. So right now I'm in this state: Class A (Win form): ClassB

Why does the OnlyOnCanceled continuation get called?

元气小坏坏 提交于 2021-02-05 07:23:10
问题 When calling await RunAsync(); on the below code, I would expect the continuation with TaskContinuationOptions.OnlyRanToCompletion continuation to run, however the OnlyOnCanceled continuation gets called (yielding the debug output "Task canceled"). Why? private static async Task RunAsync() { try { await Task.Run(() => DoWork()) .ContinueWith( (t) => { if (t?.Exception != null) { throw t.Exception; } }, TaskContinuationOptions.OnlyOnFaulted ).ContinueWith( (t) => { Debug.WriteLine("Task

What happens in the CPU when there is no user code to run?

戏子无情 提交于 2021-02-05 05:50:09
问题 It sounds reasonable that the os/rtos would schedule an "Idle task". In that case, wouldn't it be power consuming? (it sounds reasonable that the idle task will execute: while (true) {} ) 回答1: This depends on the OS and the CPU architecture. On x86 (Intel compatible) the operating system might execute HLT instructions, making the CPU wait until something interesting happens, such as a hardware interrupt. This supposedly consumes very little power. Operating systems report the time spent doing

What would be a good way to Cancel long running IO/Network operation using Tasks?

半腔热情 提交于 2021-02-04 18:25:17
问题 I've been studying Tasks in .net 4.0 and their cancellation. I like the fact that TPL tries to deal with cancellation correctly in cooperative manner. However, what should one do in situation where a call inside a task is blocking and takes a long time? For examle IO/Network. Obviously cancelling writes would be dangerous. But those are examples. Example: How would I cancel this? DownloadFile can take a long time. Task.Factory.StartNew(() => WebClient client = new WebClient(); client

What would be a good way to Cancel long running IO/Network operation using Tasks?

假装没事ソ 提交于 2021-02-04 18:25:13
问题 I've been studying Tasks in .net 4.0 and their cancellation. I like the fact that TPL tries to deal with cancellation correctly in cooperative manner. However, what should one do in situation where a call inside a task is blocking and takes a long time? For examle IO/Network. Obviously cancelling writes would be dangerous. But those are examples. Example: How would I cancel this? DownloadFile can take a long time. Task.Factory.StartNew(() => WebClient client = new WebClient(); client

Prevent UI from freezing when using Task.Result

做~自己de王妃 提交于 2021-01-29 17:02:12
问题 I am calling Task.Run(() => DoSomething()).Result which causes the UI to freeze and it happens because am using ".Result". I need Result because i want to return the value. I don't want the Method StartSomething to be async because I don't want to await the method StartSomething. I want the await to happen at DoSomething(). So basically I need a asynchronous method to be called by a synchronous method, without freezing the UI. Plus I want to return the value from the async method to the top

Restartable Tasks with timed operation

隐身守侯 提交于 2021-01-29 14:25:53
问题 I have an issue with cleaning up network-synced objects: On each tick the server sends the client (Unreliably) the states (Position, Quaternion) of objects around that player. In order to increase performance on the Client side, I wish to clean (hide or dispose) of objects that are not updated for X time. I came up with the following idea: Implement a mechanism similar to JavaScript's setTimeout . The mechanism should support mid-run termination as well as restarting with the same set of args

Synchronize C# Object Array with Database Table

时间秒杀一切 提交于 2021-01-29 08:07:01
问题 I am writing a Scheduling application, and each row in my Database Table is a different task to run at a certain time. In my application, I pull this information, and store each task in a separate object, and keep them stored in a List. As of right now, when I run my function to refresh this, there are no checks and it just adds them all again. I need to figure out the best way to see if an object already exists for the particular job, and only create a new Object for it if it doesn't. Would

Airflow: creating & passing list of tables via XCOM (without storing as a file on a drive) and setting up correct dependencies?

落花浮王杯 提交于 2021-01-29 07:15:37
问题 Here's the expected flow and dependency setting that I want to achieve: START===>Create table list(only once when DAG is triggered)===> Read & pass table names (via XCOM) ===> Create individual tasks dynamically for each table in the list===> Print table name ===>END Here's the sample code flow: start = DummyOperator( task_id = 'start', dag=dag ) end = DummyOperator( task_id = 'end', dag=dag ) #create table list: def create_source_table_list(dsn, uid, pwd, exclude_table_list, **kwargs): try: