There are plenty of reasons to use global variables instead of universal 
variables. But more importantly, a function may just modify variables, without 
caring if they're global or universal. Backgrounding the function would then 
cause different behavior based on which type of variable it is. It's tough to 
say that this is necessarily a bad thing, but it certainly would be nicer if a 
backgrounded function could modify non-universal variables from its parent 
(either global variables, or variables inherited from an outer scope).

-Kevin

On Jul 24, 2012, at 7:14 AM, Jan Kanis <jan.c...@jankanis.nl> wrote:

> I can't think of any use case that requires modifying global variables that 
> couldn't be done using universal variables, so explicitly saying '&' forks 
> the shell is  fine with me. 
> 
> It appears to be possible on Linux to give each thread its own working 
> directory etc, but even if possible the required hackery is not worth it. 
> 
> 
> On Tue, Jul 24, 2012 at 7:46 AM, Kevin Ballard <ke...@sb.org> wrote:
> If I'm backgrounding a function, I don't know what else I could possibly 
> expect other than forking. Theoretically the fork could share global 
> variables with its parent[1], so that way functions that expect to be setting 
> globals will not change behavior when backgrounded[2]. It is more work 
> though, and I don't know how much benefit there would be to trying to make 
> this work. It may be simpler just to explicitly say backgrounding a function 
> with & causes the shell to fork.
> 
> [1] similar to how all fish instances share universal variables
> [2] except for the fact that global/inherited variables could change while 
> the code is executing, but then again so could universal variables (unless 
> universal variables are only sync'd up at predefined points.. are they? And 
> if so, global/inherited variables could use the same behavior)
> 
> -Kevin
> 
> On Jul 23, 2012, at 4:24 PM, ridiculous_fish <corydo...@ridiculousfish.com> 
> wrote:
> 
> > Running functions in another thread is difficult, because so many 
> > operations act on the whole process. Think cd, set -x, etc.
> >
> > bash handles this by forking a new instance of the shell. This has the 
> > disadvantage that the function could not affect the caller (for example, 
> > change a variable) but it still seems like the best approach to me.
> >
> > _fish
> >
> > On Jul 22, 2012, at 6:49 PM, Maxim Gonchar wrote:
> >
> >> I don't know. It's bette to ask ridiculousfish about it.
> >>
> >> Maxim
> >>
> >> On Mon, 23 Jul 2012 01:33:13 +0800, Jan Kanis <j...@jankanis.nl> wrote:
> >>
> >>> But now that fish is multithreaded, it's perhaps possible to execute
> >>> background functions in a separate thread? Or is the main
> >>> function-executing part of the new fish not multithreaded?
> >>>
> >>> On Sat, Jul 21, 2012 at 4:13 AM, Maxim Gonchar <gma...@gmail.com> wrote:
> >>>
> >>>> Hi,
> >>>>
> >>>> As far as I understand, since fish do not use subshells, but executes
> >>>> functions in the same thread,
> >>>> it can not run functions in the background.
> >>>> I do not know, if there exist is a simple way to implement background
> >>>> functions.
> >>>>
> >>>> A partial workaround is to run a new fish instance to simulate a real
> >>>> subshell:
> >>>> fish -c 'q 10s'&
> >>>> fish -c 'q 3s' &
> >>>>
> >>>> Of course this way is a bit limiting: the subfish will 'see' only 
> >>>> exported
> >>>> and universal variables and only saved functions.
> >>>>
> >>>> Maxim
> >>>>
> >>>> On Sat, 21 Jul 2012 08:48:21 +0800, Steven Hum <sdot...@gmail.com> wrote:
> >>>>
> >>>>> Yeah, it is weird. A better (?) function illustrating the problem is
> >>>>>
> >>>>> function q; echo $argv;sleep $argv;echo $argv;end
> >>>>> q 10s&; q 3s&;q 6s&
> >>>>> 10s
> >>>>> 10s
> >>>>> 3s
> >>>>> 3s
> >>>>> 6s
> >>>>> 6s
> >>>>> Job 3, “q 6s&” has ended
> >>>>> Job 2, “q 3s&” has ended
> >>>>> Job 1, “q 10s&” has ended
> >>>>>
> >>>>> The sequence should be job 2,3,1, yet the function calls are completed
> >>>>> in sequence (with observed delays) 10s, 3s and 6s rather than yielding
> >>>>>
> >>>>> 10s
> >>>>> 3s
> >>>>> 6s
> >>>>> 3s
> >>>>> 6s
> >>>>> 10s
> >>>>>
> >>>>> Using ".. ;and ... ;and ... &" to join statements would still only
> >>>>> process the last command in background and not the block of commands -
> >>>>> yielding results similar to above.
> >>>>>
> >>>>> Steven
> >>>>> --
> >>>>> On Fri, 20 Jul 2012 at 03:15pm, Philip Ganchev wrote:
> >>>>>
> >>>>>> On Fri, Jul 20, 2012 at 10:51 AM, Steven Hum <sdot...@gmail.com> wrote:
> >>>>>>> I posted this in the github issues and don't mean to double post, but
> >>>>>> if
> >>>>>>> "...statement...&" is intended only to work for simple commands, e.g.
> >>>>>>>
> >>>>>>> sleep 10s&; sleep 3s&; sleep 6s&
> >>>>>>>
> >>>>>>> (silly example, I know!) then I can close the ticket as this may not
> >>>>>> be a bug
> >>>>>>> by design.
> >>>>>>>
> >>>>>>> What I found was, for functions, e.g.
> >>>>>>>
> >>>>>>> function q; echo $argv; sleep 10s; echo $argv; end
> >>>>>>>
> >>>>>>> and execute
> >>>>>>>
> >>>>>>> q 1 &; q 2 &; q 3 &
> >>>>>>>
> >>>>>>> the output is
> >>>>>>>
> >>>>>>> 1
> >>>>>>> 1
> >>>>>>> 2
> >>>>>>> 2
> >>>>>>> 3
> >>>>>>> 3
> >>>>>>> Job 3, “q 3 &” has ended
> >>>>>>> Job 2, “q 2 &” has ended
> >>>>>>> Job 1, “q 1 &” has ended
> >>>>>> [...]
> >>>>>>
> >>>>>> This is very surprising to me. I'm curious about the rationale here. I
> >>>>>> would expect the output:
> >>>>>>
> >>>>>> 1
> >>>>>> 2
> >>>>>> 3
> >>>>>> 1
> >>>>>> Job 1, “q 1 &” has ended
> >>>>>> 2
> >>>>>> Job 2, “q 2 &” has ended
> >>>>>> 3
> >>>>>> Job 3, “q 3 &” has ended
> >>>>>>
> >>>>>>> If there is a correct "fish" way of spawning background function
> >>>>>> processes, my
> >>>>>>> second question is: is there a way to spawn a block of commands in
> >>>>>> background
> >>>>>>> similar to POSIX "(command1 && command2 && command3...) &". I tried
> >>>>>> "begin;
> >>>>>>> ...statements...; end &" but fish does not like that either (not
> >>>>>> surprisingly
> >>>>>>> given the above!)
> >>>>>>
> >>>>>> command1; and command2; and command3
> >>>>>>
> >>>>>> [...]
> >>>>>
> >>>>>
> >>>>>
> >>>> ------------------------------------------------------------------------------
> >>>>> Live Security Virtual Conference
> >>>>> Exclusive live event will cover all the ways today's security and
> >>>>> threat landscape has changed and how IT managers can respond. 
> >>>>> Discussions
> >>>>> will include endpoint security, mobile security and the latest in 
> >>>>> malware
> >>>>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> >>>>> _______________________________________________
> >>>>> Fish-users mailing list
> >>>>> Fish-users@lists.sourceforge.net
> >>>>> https://lists.sourceforge.net/lists/listinfo/fish-users
> >>>>
> >>>>
> >>>> ------------------------------------------------------------------------------
> >>>> Live Security Virtual Conference
> >>>> Exclusive live event will cover all the ways today's security and
> >>>> threat landscape has changed and how IT managers can respond. Discussions
> >>>> will include endpoint security, mobile security and the latest in malware
> >>>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> >>>> _______________________________________________
> >>>> Fish-users mailing list
> >>>> Fish-users@lists.sourceforge.net
> >>>> https://lists.sourceforge.net/lists/listinfo/fish-users
> >>
> >
> >
> > ------------------------------------------------------------------------------
> > Live Security Virtual Conference
> > Exclusive live event will cover all the ways today's security and
> > threat landscape has changed and how IT managers can respond. Discussions
> > will include endpoint security, mobile security and the latest in malware
> > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> > _______________________________________________
> > Fish-users mailing list
> > Fish-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/fish-users
> 
> 

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to