I haven't measured this precisely but it seems the default timeout value for retrieving EntityValue
s with *Data
functions is in the range of tens of seconds. This significantly impacts the execution time if the *Data
function is called repeatedly, because I often get an
EntityValue::timeout: A network operation for EntityValue timed out. Please try again later. >>
error.
Is it possible to manually set the timeout value for such functions that retrieve curated data from Wolfram servers?
Answer
You could wrap the call to the *Data function in TimeConstrained
. This function will evaluate its argument for the maximum number of seconds specified. If the computation has not completed in that time, it will return $Aborted
. Of course, you will probably have to manage the aborted computation somehow, but from my reading of your question that doesn't seem to be a problem.
For instance:
TimeConstrained[WeatherData["Chicago", "Temperature", {1950, 1}], 0.1]
returns $Aborted
on my system; if I use a more lax time constrain, e.g. 1 s, I obtain my result.
This problem is particularly relevant for data that need download and initialization of a local archive / index when first accessed, such as the WeatherData
results above. The TimeConstrained
function will stop the loading of the database as well as the data processing in that case.
As an aside, the database loading is incremental in those cases: if you execute the same time-limited expression enough times, it will download and process a small chunk each time, until at the end it will have downloaded everything it needs and will be able to answer from local data, which will be very fast.
Comments
Post a Comment