Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tcpsocket and @async problem #10589

Closed
freddycct opened this issue Mar 20, 2015 · 13 comments
Closed

Tcpsocket and @async problem #10589

freddycct opened this issue Mar 20, 2015 · 13 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@freddycct
Copy link

function f()
    task1 = @async begin
        server = listen(2000)
        socket = accept(server)
    end

    socket = wait(task1)
    println(typeof(socket))
end

f()

Error: socket is undefined

I get the error that socket is undefined. This works in REPL but not when the program is executed from inside a function f()

Note: Julia v 0.36

@pao
Copy link
Member

pao commented Mar 20, 2015

This is #10405, which is fixed on master. I am not sure if it's suitable for backport since someone might be relying on that behavior. @tkelman?

@pao pao closed this as completed Mar 20, 2015
@freddycct
Copy link
Author

So only available on v0.4 but not v0.3+ ?

@pao
Copy link
Member

pao commented Mar 20, 2015

Not currently, no.

@tkelman
Copy link
Contributor

tkelman commented Mar 20, 2015

There have been a bunch of intermittent TypeErrors and other CI instabilities that seem to be related (or uncovered?) by that one so I would vote against backporting that change.

@freddycct
Copy link
Author

So how do I get access to variables computed inside an @async begin ... end ?

@Keno
Copy link
Member

Keno commented Mar 21, 2015

@pao Can you explain how this is #10405? I also see the same behavior on master.

@Keno
Copy link
Member

Keno commented Mar 21, 2015

Anyway, the problem here is the extra socket in the @async block (please note to put quotes around macro name to avoid notifying github users). Without it works fine:

julia> function f()
           task1 = @async begin
               server = listen(2000)
               accept(server)
           end

           socket = wait(task1)
           println(typeof(socket))
       end
f (generic function with 1 method)

julia> f()
TCPSocket

@freddycct
Copy link
Author

So is there any bug? Please reopen if this is not the same as #10405. I don't see why I can't use socket = accept(server), I thought everything inside @async is localized. infact the following fails too with the return statement...

function f()
    task1 = @async begin
        server = listen(2000)
        socket = accept(server)
        return socket
    end

    socket = wait(task1)
    println(typeof(socket))
end

f()

@Keno
Copy link
Member

Keno commented Mar 21, 2015

Well, it's hard to say. It's basically working as expected within the semantics of the language, because inner function capture locals:

julia> function f()
       g() = x
       x = 1
       g
       end
f (generic function with 1 method)

julia> f()()
1

with the inherent consequence that if you use the local (in the task) before it's assigned you get an error. So everything is working as intended, though it may be surprising.

@Keno
Copy link
Member

Keno commented Mar 21, 2015

I guess the macro could recognize variables that are only assigned, but not read before? @JeffBezanson does that seem reasonable?

@Keno Keno reopened this Mar 21, 2015
@pao
Copy link
Member

pao commented Mar 22, 2015

Can you explain how this is #10405?

From the description in the original issue, it was an error from an async task which wasn't being reported, which is exactly #10405. But it appears you have this under control.

@freddycct
Copy link
Author

It works when I use different variable names and not use the same variable name in @async

function f()
    task1 = @async begin
        server = listen(2000)
        socket = accept(server)
    end

    socket_1 = wait(task1)
    println(typeof(socket_1))
end

f()

@ihnorton ihnorton added the io Involving the I/O subsystem: libuv, read, write, etc. label Mar 28, 2015
@JeffBezanson JeffBezanson added bug Indicates an unexpected problem or unintended behavior and removed io Involving the I/O subsystem: libuv, read, write, etc. labels Jul 15, 2015
@JeffBezanson JeffBezanson self-assigned this Jul 15, 2015
@JeffBezanson
Copy link
Member

dup of #2669

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

6 participants