Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In working on a custom stock screener, I often need to run mathematica code like this:

{#, FinancialData[#, "DividendYield"]} & /@ Take[FinancialData["NYSE:*"], 30]

In this example, I've limited the result set to 30, but ideally I'd like to get the dividend yield for a much larger set.

This is a specific example of a more general problem I have with mathematica, which is that sometimes I need to run a large number of distinct network IO calls and this blocks further computations.

Is there some workaround for writing calls like this that won't block further computations? I am a fairly competent programmer and therefore can implement a system in my Mathematica code to compute results one at a time, but I am trying to avoid reinventing the wheel. I feel this must be a very common problem for Mathematica users who use the built in data sources/Wolfram|Alpha integration.

share|improve this question
2  
You can start two distinct kernels (or better: two instances of Mathematica front end too, if you're not on a Mac). But then they won't share variables. Alternatively you can evaluate in a subkernel. The relevant functions are ParallelSubmit and Parallel`Developer`QueueRun. –  Szabolcs Mar 13 '12 at 13:53
    
Thank you. I will look into the documentation for those calls and do some experimentation. –  achristi Mar 13 '12 at 13:56
    
I'll post a full answer tomorrow if I have time, or hopefully someone else will do it before that. –  Szabolcs Mar 13 '12 at 13:56
    
@Szabolcs one can start multiple mma frontends on a mac too (by directly exectuing the relevant file inside the Mathematica.app bundle) –  acl Mar 13 '12 at 14:30
    
@acl I never used a Mac, I've just been told that it's not easy to do it, and I wanted to avoid another comment about that. Two kernels should suffice anyway, I just prefer two front ends for these things in case I crash or (more likely) freeze one of them. –  Szabolcs Mar 13 '12 at 14:55
add comment

1 Answer 1

up vote 9 down vote accepted

As Szabolcs mentions, the simplest way to do this is to start a new kernel and push this bulk of data acquisition to that kernel and let it run in the background. There are good examples in the documentation in tutorial/ConcurrencyManagingParallelProcesses.

For your specific case, here's an example following the above:

LaunchKernels[1];
j = ParallelSubmit[{#, FinancialData[#, "DividendYield"]} & /@ 
   Take[FinancialData["NYSE:*"], 30]];

enter image description here

Parallel`Developer`QueueRun[]
Out[3]= True

enter image description here

You can continue working as usual in your main kernel.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.