I'm working on a visualisation app with Processing.
All appears to be going well, but I've noticed that in the console, I'm seeing any println() statements from the setup() method in triplicate. This doesn't appear to be the case for similar statements inside the draw() loop.
I thought this might just be an output thing, but I'm now seeing multiple attempts to open files. It will likely be taking its toll on performance, too.
Any idea how I can prevent this?
I'm using Processing 1.0.9 on Mac OS 10.6.3.
Thanks in advance,
Ross
Calls to size() and/or hint() cause setup() to be run again. Put those calls first to prevent other code (e.g. file loading) being affected.
Related
I have a complex code in AsyncTask, which makes alot of I / O on SQLite and heavy calculation. This piece of code is very long and that's why I did not copy it here. When my code is commented AsyncTask works very well and update progress bar correctly, but with my code, the progress bar is frozen until at the end of my code.
Can anyone give me recommendations to respect, to write the program like mine with of course, a worker thread and a progress bar that works well?
I finished my project. in phase of development, I had no problem. but in phase testing with real data I am confronted with this problem. It's been three days that I read on a AsyncTask discussed on this forum but neither my help and I do not know what to do. I also frozen.
Thank you for your help.
The problem is resolved.
Apparently my code uses alot of CPU time and does not leave enough time for UIThread to update the screen.
So I set the portion of code that accede SQLite in another thread using a Handler and a CountDownLatch with 10ms delay to start the thread. and this delay allows android has to release time for UIThread to refresh. this way, publishProgress started working. Now I wonder if it's a good solution.
I'm trying to use a coroutine function outside of the event loop. (In this case, I want to call a function in Django that could also be used inside the event loop too)
There doesn't seem to be a way to do this without making the calling function a coroutine.
I realize that Django is built to be blocking and a therefore incompatible with asyncio. Though I think that this question might help people who are making the transition or using legacy code.
For that matter, it might help to understand async programming and why it doesn't work with blocking code.
After a lot of research I think these solutions could be helpful:
Update your legacy code to use asyncio:
Yes i know that it can be hard and painful, but it might be the sanest choice. If you are wanting to use Django like I was... Well, you've got a lot of work to do to make Django async'd. I'm not sure it is possible, but I found at least one attempt: https://github.com/aaugustin/django-c10k-demo (Though, in a youtube video the author explained all the shortcomings of this).
use asyncio.async or asyncio.Task:
These items will enable you to run something async inside of blocking code, but the downfall here is that you will not be able to wait for them to finish without doing something ugly like a while loop that checks if the future has completed... ugh, but if you don't need the result, that might work for you.
About case #2: Blocking code should be at least wrapped with .run_in_executor.
In a jnlp application, we create a modal popup extends from javax.swing.JDialog, and call dispose() to hide the dialog whenever necessary. However, sometimes the final client get repainting problem. The dialog doesn't really disappear, and its parent window look messy. I couldn't reproduce, but it happen many times on final client PC. I guess there are 2 possible reasons:
There is a thread in our application update the cursor directly. However, I can't prove this thread is the root cause of the issue.
Periodically, we have another process highly use the CPU in a few seconds. I tried to load the CPU, but I couldn't reproduce the issue too.
Any advice for me in this case?
Thanks!
It looks the answer is in the question ;-)
Having a thread (not the EDT) updating the UI (the cursor in your case) may lead to this kind of problem.
Hence, ensure that your thread calls SwingUtilities.invokeLater() (or invokeAndWait() depending on your needs).
Another possibility (but this depends a lot on what your thread does, without further description from your side, it is hard to tell) would be to use SwingWorker instead of a thread.
i have a function which costs plenty of time.
this function is an sql-query called via odbc - not written in x++, since the functional range is insufficient.
while this operation is running, I want to show an animation on a form - defined in the aviFiles-macro.
trying to realize, several problems occur:
the animation doesn't start prior the function has finished.
using threads won't fulfill my hopes, since the odbc-settings are made on the server and i guess, the function is called on client-side.
besides - how am i able to get the information that the treaded task has ended up?
could anyone give me a hint, how to
play an animation on a form
do something ( in background ) and go on playing the animation until the task to perform is finished
stop the animation
coding this in exactly this order shows the behaviour mentioned above.
thanks in advance for hints and help!
You can use standard AotFind as an example:
split the work in small pieces each
piece should be executed at timer
tick
Also, you can try not to use timer, but to call infolog.yield() as often as possible.
this could potentially be done in a very complicated way with call backs and delegates if your odbc is in a vs project...
but isn't the real solution to try to find a faster/more effective way to query your data?
Is anyone aware of a way to receive NSURLDownload's delegate methods on a separate thread, i.e. not the main one? I am using an NSOperationQueue to manage them but at the moment I need to use the performSelectorOnMainThread method to get it too work. The problem with this is that it drives the kernel task crazy reaching about 30% of CPU cycles. Curiously this has only happened since upgrading to SL, when NSOperationQueue changed behaviour (not that I am dissing it, GCD rocks!)
Thanks
Colin
My first question is, what are you using NSURLDownload to do? Are you just downloading a bunch of files to the disk, or do you really want the data in memory?
If you're downloading a bunch of files to the disk and you don't want to do any special processing, I'd first try just firing off all the NSURLDownloads on the main thread, without bothering with an NSOperationQueue... I mean, how many operations are we talking about? Can they all run concurrently? The callbacks on the main thread shouldn't be too much of a problem, unless you are doing something heavyweight when you get notified you got some data, in which case it seems like...
Otherwise, I'd switch to using NSURLConnection. It's specifically documented to call you back on the thread you set it up on, and is more flexible. Of course, it's not as high-level, so if you really want files saved to disk, you're going to have to write the I/O yourself. Shouldn't be a huge hardship - it's like four extra lines of code.
-W
NSOperationQueue changed behaviour because it was buggy. It's seems really solid now but yeah, it has a different personality.
Reference (http://www.mikeash.com/?page=pyblog/dont-use-nsoperationqueue.html)
Can you give more info on your problem? Do you only need to notify when the download is finished? Are you doing many downloads at once?