Search Results

Search found 734 results on 30 pages for 'yield'.

Page 2/30 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Is there a way to efficiently yield every file in a directory containing millions of files?

    - by Josh Smeaton
    I'm aware of os.listdir, but as far as I can gather, that gets all the filenames in a directory into memory, and then returns the list. What I want, is a way to yield a filename, work on it, and then yield the next one, without reading them all into memory. Is there any way to do this? I worry about the case where filenames change, new files are added, and files are deleted using such a method. Some iterators prevent you from modifying the collection during iteration, essentially by taking a snapshot of the state of the collection at the beginning, and comparing that state on each move operation. If there is an iterator capable of yielding filenames from a path, does it raise an error if there are filesystem changes (add, remove, rename files within the iterated directory) which modify the collection? There could potentially be a few cases that could cause the iterator to fail, and it all depends on how the iterator maintains state. Using S.Lotts example: filea.txt fileb.txt filec.txt Iterator yields filea.txt. During processing, filea.txt is renamed to filey.txt and fileb.txt is renamed to filez.txt. When the iterator attempts to get the next file, if it were to use the filename filea.txt to find it's current position in order to find the next file and filea.txt is not there, what would happen? It may not be able to recover it's position in the collection. Similarly, if the iterator were to fetch fileb.txt when yielding filea.txt, it could look up the position of fileb.txt, fail, and produce an error. If the iterator instead was able to somehow maintain an index dir.get_file(0), then maintaining positional state would not be affected, but some files could be missed, as their indexes could be moved to an index 'behind' the iterator. This is all theoretical of course, since there appears to be no built-in (python) way of iterating over the files in a directory. There are some great answers below, however, that solve the problem by using queues and notifications. Edit: The OS of concern is Redhat. My use case is this: Process A is continuously writing files to a storage location. Process B (the one I'm writing), will be iterating over these files, doing some processing based on the filename, and moving the files to another location. Edit: Definition of valid: Adjective 1. Well grounded or justifiable, pertinent. (Sorry S.Lott, I couldn't resist). I've edited the paragraph in question above.

    Read the article

  • Flame Experiments Aboard the ISS Yield Surprising Results

    - by Jason Fitzpatrick
    Recent flame-based experiments aboard the International Space Station yielded results scientists simply thought couldn’t happen–combustion in microgravity is a curious thing. Smithsonian magazine reports on the findings: Here on Earth, when a flame burns, it heats the surrounding atmosphere, causing the air to expand and become less dense. The pull of gravity draws colder, denser air down to the base of the flame, displacing the hot air, which rises. This convection process feeds fresh oxygen to the fire, which burns until it runs out of fuel. The upward flow of air is what gives a flame its teardrop shape and causes it to flicker. But odd things happen in space, where gravity loses its grip on solids, liquids and gases. Without gravity, hot air expands but doesn’t move upward. The flame persists because of the diffusion of oxygen, with random oxygen molecules drifting into the fire. Absent the upward flow of hot air, fires in microgravity are dome-shaped or spherical—and sluggish, thanks to meager oxygen flow. “If you ignite a piece of paper in microgravity, the fire will just slowly creep along from one end to the other,” says Dietrich. “Astronauts are all very excited to do our experiments because space fires really do look quite alien.” Hit up the link below for the full article including how NASA is applying the findings. Why Does 64-Bit Windows Need a Separate “Program Files (x86)” Folder? Why Your Android Phone Isn’t Getting Operating System Updates and What You Can Do About It How To Delete, Move, or Rename Locked Files in Windows

    Read the article

  • Difference between Thread.Sleep(0) and Thread.Yield()

    - by Xose Lluis
    As Java has had Sleep and Yield from long ago, I've found answers for that platform, but not for .Net .Net 4 includes the new Thread.Yield() static method. Previously the common way to hand over the CPU to other process was Thread.Sleep(0). Apart from Thread.Yield() returning a boolean, are there other performance, OS internals differences? For example, I'm not sure if Thread.Sleep(0) checks if other thread is ready to run before changing the current Thread to waiting state... if that's not the case, when no other threads are ready, Thread.Sleep(0) would seem rather worse that Thread.Yield().

    Read the article

  • Error in merging two sequences of timestamps to yield strings

    - by AruniRC
    The code sorts two input sequences - seq01 and seq02 - on the basis of their timestamp values and returns a sequence that denotes which sequence is to be read for the values to be in order. For cases where seq02's timestamp value is lesser than seq01's timestamp value we yield a "2" to the sequence being returned, else a "1". These denote whether at that point seq01 is to be taken or seq02 is to be taken for the data to be in order (by timestamp value). let mergeSeq (seq01:seq<_>) (seq02:seq<_>) = seq { use iter01 = seq01.GetEnumerator() use iter02 = seq02.GetEnumerator() while iter01.MoveNext() do let _,_,time01 = iter01.Current let _,_,time02 = iter02.Current while time02 < time01 && iter02.MoveNext() do yield "2" yield "1" } To test it in the FSI created two sequences a and b, a={1;3;5;...} and b={0;2;4;...}. So the expected values for let c = mergeSeq a b would have been {"2","1","2","1"...}. However I am getting this error: error FS0001: The type ''a * 'b * 'c' does not match the type 'int' EDIT After correcting: let mergeSeq (seq01:seq<_>) (seq02:seq<_>) = seq { use iter01 = seq01.GetEnumerator() use iter02 = seq02.GetEnumerator() while iter01.MoveNext() do let time01 = iter01.Current let time02 = iter02.Current while time02 < time01 && iter02.MoveNext() do yield "2" yield "1" } After running this, there's another error: call MoveNext. Somehow the iteration is not being performed.

    Read the article

  • yield returns within lock statement

    - by DayOne
    Hi eveybody, if i have a yield return in a lock statement does the lock get taken out on each yield (5 times in the example below) or only once for all the items in the list? Thanks private List<string> _data = new List<string>(){"1","2","3","4","5"}; private object _locker =new object(); public IEnumerable<string> GetData() { lock (_locker) { foreach (string s in _data) { yield return s; } } }

    Read the article

  • Stepping over a yield statement

    - by EoghanM
    When in the Python debugger (pdb) I want to step over a yield statement, but hitting (n) for next brings me to the destination of the yield i.e. the consumer of the generator. I want to go to the next line that is executed within the generator. Is there any way to do this? I'm using Python 2.6

    Read the article

  • Yield and default case || do not output default case

    - by coulix
    Hello Railers, I have a simple yield use case and for some unknown reason the default case is never shown: In my super_admin layout I have: <%= yield :body_id || 'super_admin_main' %> My controller class Superadmin::GolfsController < ApplicationController layout "super_admin" def show end end My show view With or without <% content_for(:body_id) do %sadmin_golfs<% end % With: sadmin_golfs is shown. without: empty string is shown instead of super_admin_main Can anyone reproduce the same behavior ? Rails 3

    Read the article

  • What do you think of this iterator syntax?

    - by ChaosPandion
    I've been working on an ECMAScript dialect for quite some time now and have reached a point where I am comfortable adding new language features. I would love to hear some thoughts and suggestions on the syntax. Example iterator Numbers { yield 1; yield 2; yield 3; if (true) { yield break; } yield continue iterator { yield 4; yield 5; yield 6; }; } Syntax IteratorDeclaration:     iterator  Identifier  {  IteratorBody  } IteratorExpression:     iterator  Identifieropt  {  IteratorBody  } IteratorBody:     IteratorStatementsopt IteratorStatements:     IteratorStatement IteratorStatementsopt IteratorStatement:     Statement but not one of BreakStatement ContinueStatement ReturnStatement     YieldStatement     YieldBreakStatement     YieldContinueStatement YieldStatement:     yield  Expression  ; YieldBreakStatement:     yield  break  ; YieldContinueStatement:     yield  continue  Expression  ;

    Read the article

  • Is yield break equivalent to returning Enumerable<T>.Empty from a method returning IEnumerable<T>

    - by Mike Two
    These two methods appear to behave the same to me public IEnumerable<string> GetNothing() { return Enumerable.Empty<string>(); } public IEnumerable<string> GetLessThanNothing() { yield break; } I've profiled each in test scenarios and I don't see a meaningful difference in speed, but the yield break version is slightly faster. Are there any reasons to use one over the other? Is one easier to read than the other? Is there a behavior difference that would matter to a caller?

    Read the article

  • What is the best way to translate this recursive python method into Java?

    - by Simucal
    In another question I was provided with a great answer involving generating certain sets for the Chinese Postman Problem. The answer provided was: def get_pairs(s): if not s: yield [] else: i = min(s) for j in s - set([i]): for r in get_pairs(s - set([i, j])): yield [(i, j)] + r for x in get_pairs(set([1,2,3,4,5,6])): print x This will output the desire result of: [(1, 2), (3, 4), (5, 6)] [(1, 2), (3, 5), (4, 6)] [(1, 2), (3, 6), (4, 5)] [(1, 3), (2, 4), (5, 6)] [(1, 3), (2, 5), (4, 6)] [(1, 3), (2, 6), (4, 5)] [(1, 4), (2, 3), (5, 6)] [(1, 4), (2, 5), (3, 6)] [(1, 4), (2, 6), (3, 5)] [(1, 5), (2, 3), (4, 6)] [(1, 5), (2, 4), (3, 6)] [(1, 5), (2, 6), (3, 4)] [(1, 6), (2, 3), (4, 5)] [(1, 6), (2, 4), (3, 5)] [(1, 6), (2, 5), (3, 4)] This really shows off the expressiveness of Python because this is almost exactly how I would write the pseudo-code for the algorithm. I especially like the usage of yield and and the way that sets are treated as first class citizens. However, there in lies my problem. What would be the best way to: 1.Duplicate the functionality of the yield return construct in Java? Would it instead be best to maintain a list and append my partial results to this list? How would you handle the yield keyword. 2.Handle the dealing with the sets? I know that I could probably use one of the Java collections which implements that implements the Set interface and then using things like removeAll() to give me a set difference. Is this what you would do in that case? Ultimately, I'm looking to reduce this method into as concise and straightforward way as possible in Java. I'm thinking the return type of the java version of this method will likely return a list of int arrays or something similar. How would you handle the situations above when converting this method into Java?

    Read the article

  • Yield In VB.NET

    - by MagicKat
    C# has the keyword called yield. VB.NET lacks this keyword. I am curious how some of the VB programmers have gotten around the lack of this keyword. Do you implement your own iterator class? Or do you try and code to avoid the need of an iterator? The yield keyword does force the compiler to do some coding behind the scenes. http://blogs.msdn.com/oldnewthing/archive/2008/08/12/8849519.aspx is a good example of that.

    Read the article

  • Is this a dangerous locking pattern?

    - by Martin
    I have an enumerator written in C#, which looks something like this: try { ReadWriteLock.EnterReadLock(); yield foo; yield bar; yield bash; } finally { ReadWriteLock.ExitReadLock(); } I believe this may be a dangerous locking pattern, as the ReadWriteLock will only be released if the enumeration is complete, otherwise the lock is left hanging and is never released, am I correct? If so, what's the best way to combat this?

    Read the article

  • Collection type generated by for with yield

    - by Jesper
    When I evaluate a for in Scala, I get an immutable IndexedSeq (a collection with array-like performance characteristics, such as efficient random access): scala> val s = for (i <- 0 to 9) yield math.random + i s: scala.collection.immutable.IndexedSeq[Double] = Vector(0.6127056766832756, 1.7137598183155291, ... Does a for with a yield always return an IndexedSeq, or can it also return some other type of collection class (a LinearSeq, for example)? If it can also return something else, then what determines the return type, and how can I influence it? I'm using Scala 2.8.0.RC3.

    Read the article

  • Java concurrency - Should block or yield?

    - by teto
    Hi, I have multiple threads each one with its own private concurrent queue and all they do is run an infinite loop retrieving messages from it. It could happen that one of the queues doesn't receive messages for a period of time (maybe a couple seconds), and also they could come in big bursts and fast processing is necessary. I would like to know what would be the most appropriate to do in the first case: use a blocking queue and block the thread until I have more input or do a Thread.yield()? I want to have as much CPU resources available as possible at a given time, as the number of concurrent threads may increase with time, but also I don't want the message processing to fall behind, as there is no guarantee of when the thread will be reescheduled for execution when doing a yield(). I know that hardware, operating system and other factors play an important role here, but setting that aside and looking at it from a Java (JVM?) point of view, what would be the most optimal?

    Read the article

  • yield in ERB without rails

    - by fursie
    Hi How can I use yield for template inheritance in erb? I want to use erb in a plain ruby CGI script and want to use a base template and subtemplate like it Rails with the application template does.

    Read the article

  • Passing multiple codeblocks as arguments

    - by doctororange
    I have a method which takes a code block. def opportunity @opportunities += 1 if yield @performances +=1 end end and I call it like this: opportunity { @some_array.empty? } But how do I pass it more than one code block so that I could use yield twice, something like this: def opportunity if yield_1 @opportunities += 1 end if yield_2 @performances +=1 end end and: opportunity {@some_other_array.empty?} { @some_array.empty? } I am aware that this example could be done without yield, but it's just to illustrate. Thanks.

    Read the article

  • haml / rails: yield title with german umlauts

    - by Maxem
    Hi, I would like to do something like this in my application layout: %title= "#{yield(:sub_title)} - Page Name" and in a real view - content_for :sub_title do Übersicht # I tried &Uuml;bersicht, != "&Uuml;bersicht" and a bunch of other methods what happens is, I either get the black pound with the question mark in it - wrong encoding or the raw string (&UumI;bersicht). Does anyone know a way how to get this to work? Another requirement is that I'd like to show user generated content in the title and this content may or may not have umlauts in it. Used versions: Haml 3.0.11, Rails 3 beta4 and currently for development JRuby 1.5

    Read the article

  • Custom Collection Implementing IEnumerable

    - by Burnzy
    I know that technically, an Interface is used for reading and not writting or editing however, I want to add an add and addrange function to the following class, here is what I currently have which is not working public class HrefCollection : IEnumerable<Href> { private IEnumerable<Href> hrefs; public IEnumerable<Href> Add( Href href ) { yield return href; } public IEnumerable<Href> AddRange( List<Href> hrefs ) { foreach( Href href in hrefs ) { yield return href; } } public IEnumerator<Href> GetEnumerator() { return hrefs.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return hrefs.GetEnumerator(); } } I'm not quite sure how to associate the yield return with the private list. Thanks for your help!

    Read the article

  • Is it possible to implement an infinite IEnumerable without using yield with only C# code?

    - by sinelaw
    This isn't a practical problem, it's more of a riddle. Problem I'm curious to know if there's a way to implement something equivalent to the following, but without using yield: IEnumerable<T> Infinite<T>() { while (true) { yield return default(T); } } Rules You can't use the yield keyword Use only C# itself directly - no IL code, no constructing dynamic assemblies etc. You can only use the basic .NET lib (only mscorlib.dll, System.Core.dll? not sure what else to include). However if you find a solution with some of the other .NET assemblies (WPF?!), I'm also interested. Don't implement IEnumerable or IEnumerator. Notes The closest I've come yet: IEnumerable<int> infinite = null; infinite = new int[1].SelectMany(x => new int[1].Concat(infinite)); This is "correct" but hits a StackOverflowException after 14399 iterations through the enumerable (not quite infinite). I'm thinking there might be no way to do this due to the CLR's lack of tail recursion optimization. A proof would be nice :)

    Read the article

  • Rails fields_for parameters for a has_many relation don't yield an Array in params

    - by user1289061
    I have a model Sensor with has_many and accepts_nested_attributes_for relationships to another model Watch. In a form to update a Sensor, I have something like the following <%= sensor_form.fields_for :watches do |watches_form| %> <%= watches_form.label :label %><br /> <%= watches_form.text_field :label %> <% end %> This is indended to allow editting of the already-created Watches belonging to a Sensor. This call spits form inputs as so: <input name="sensor[watches_attributes][0][label]" ... /> <input name="sensor[watches_attributes][0][id]" ... /> When this gets submitted, the params object in the Sensor controller gets an assoc like "sensor" => { "id"=>"1", "watches_attributes"=> { "0"=>{"id" => "1", "label" => "foo"}, "1"=>{"id" => "2", "label" => "bar"} } } For a has_many, accepts_nested_attributes_for update to work upon the @sensor.update_attributes call, it seems that that attributes key really must map to an Array. From what I've seen in the examples, the combination of has_many, accepts_nested_attributes_for, and sensor_form.fields_for should allow me to pass the resulting params object directly to @sensor.update_attributes and update each related object as intended. Instead the Sensor takes place, with no errors, but the Watch objects are not updated (since "watches_attributes" maps to a Hash instead of an Array?) Have I missed something?

    Read the article

  • XamlXmlReader.Read() does not yield matching XamlNodeType.StartObject and XamlNodeType.EndObject on

    - by Yuval
    Hi, I am trying to parse a valid xaml file using the XamlXmlReader. It looks like it is 'skipping' some elements when when Read() is called. for example on the following xaml snippet: <UserControl.Resources> <Converters:AnyDbTypeToDisplayNameConverter x:Key="anyDbTypeToDisplayNameConverter" /> </UserControl.Resources> when reading I first get a XamlNodeType.StartObject on UserControl.Resources - makes sense then another XamlNodeType.StartObject on Converters - also cool. but then i do not get a XamlNodeType.EndObject on the Converters and immediately jump to the next line and does not report a XamlNodeType.StartObject. Any Idea if this is working as design ? looks like a bug to me

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >