puniverse / pulsar

Fibers, Channels and Actors for Clojure
http://docs.paralleluniverse.co/pulsar/
Other
911 stars 53 forks source link

Spawning fn from other namespace doesn't work #44

Closed ulises closed 9 years ago

ulises commented 9 years ago

Apologies for the vagueness of the title of this issue, but here's what's happening: 1) create function in a namespace, e.g. n/f 2) in a different namespace try to spawn this function, e.g. (a/spawn n/f) 3) exception happens:

Exception in Fiber "fiber-10000001" If this exception looks strange, perhaps you've forgotten to instrument a blocking method. Run your program with -Dco.paralleluniverse.fibers.verifyInstrumentation to catch the culprit!
java.lang.ClassCastException: co.paralleluniverse.pulsar.actors$reify__6559 cannot be cast to clojure.lang.IFn
    at sliver.node$f.invoke(node.clj:203)
    at co.paralleluniverse.pulsar.InstrumentedIFn.invoke(InstrumentedIFn.java:32)
    at co.paralleluniverse.pulsar.ClojureHelper.suspendableInvoke(ClojureHelper.java:213)
    at co.paralleluniverse.pulsar.ClojureHelper$4.run(ClojureHelper.java:200)
    at co.paralleluniverse.actors.PulsarActor.doRun(PulsarActor.java:92)
    at co.paralleluniverse.actors.Actor.run0(Actor.java:691)
    at co.paralleluniverse.actors.ActorRunner.run(ActorRunner.java:51)
    at co.paralleluniverse.fibers.Fiber.run(Fiber.java:1024)
WARNING: Uninstrumented methods (marked '**') or call-sites (marked '!!') detected on the call stack: 
    at sliver.node$f.invoke (node.clj:203) **
    at co.paralleluniverse.pulsar.InstrumentedIFn.invoke (InstrumentedIFn.java:32)
    at co.paralleluniverse.pulsar.ClojureHelper.suspendableInvoke (ClojureHelper.java:213) (optimized)
    at co.paralleluniverse.pulsar.ClojureHelper$4.run (ClojureHelper.java:200)
    at co.paralleluniverse.actors.PulsarActor.doRun (PulsarActor.java:92)
    at co.paralleluniverse.actors.Actor.run0 (Actor.java:691)
    at co.paralleluniverse.actors.ActorRunner.run (ActorRunner.java:51)
    at co.paralleluniverse.fibers.Fiber.run (Fiber.java:1024)
    at co.paralleluniverse.fibers.Fiber.run1 (Fiber.java:1019)
Exception in Fiber "fiber-10000001" If this exception looks strange, perhaps you've forgotten to instrument a blocking method. Run your program with -Dco.paralleluniverse.fibers.verifyInstrumentation to catch the culprit!
java.lang.ClassCastException: co.paralleluniverse.pulsar.actors$reify__6559 cannot be cast to clojure.lang.IFn
    at sliver.node$f.invoke(node.clj:203)
    at co.paralleluniverse.pulsar.InstrumentedIFn.invoke(InstrumentedIFn.java:32)
    at co.paralleluniverse.pulsar.ClojureHelper.suspendableInvoke(ClojureHelper.java:213)
    at co.paralleluniverse.pulsar.ClojureHelper$4.run(ClojureHelper.java:200)
    at co.paralleluniverse.actors.PulsarActor.doRun(PulsarActor.java:92)
    at co.paralleluniverse.actors.Actor.run0(Actor.java:691)
    at co.paralleluniverse.actors.ActorRunner.run(ActorRunner.java:51)
    at co.paralleluniverse.fibers.Fiber.run(Fiber.java:1024)
WARNING: Uninstrumented methods (marked '**') or call-sites (marked '!!') detected on the call stack: 
    at sliver.node$f.invoke (node.clj:203) **
    at co.paralleluniverse.pulsar.InstrumentedIFn.invoke (InstrumentedIFn.java:32)
    at co.paralleluniverse.pulsar.ClojureHelper.suspendableInvoke (ClojureHelper.java:213) (optimized)
    at co.paralleluniverse.pulsar.ClojureHelper$4.run (ClojureHelper.java:200)
    at co.paralleluniverse.actors.PulsarActor.doRun (PulsarActor.java:92)
    at co.paralleluniverse.actors.Actor.run0 (Actor.java:691)
    at co.paralleluniverse.actors.ActorRunner.run (ActorRunner.java:51)
    at co.paralleluniverse.fibers.Fiber.run (Fiber.java:1024)
    at co.paralleluniverse.fibers.Fiber.run1 (Fiber.java:1019)

relevant bits of code:

  :dependencies [[org.clojure/clojure "1.6.0"]
                 [co.paralleluniverse/pulsar "0.7.3"]]
  :java-agents [[co.paralleluniverse/quasar-core "0.7.3"]]
(ns sliver.node
  (:require [co.paralleluniverse.pulsar.actors :as a]))

(defn f [] (println (a/self)))
(ns sliver.core
  (:require [sliver.node :as n]
            [co.paralleluniverse.pulsar.actors :as a]))

(a/spawn n/f)

If this is a case of RTFM, that's great, please point me to the docs. If not, then :(

ulises commented 9 years ago

FYI, I came across this while writing some tests whereby actors expose their self via promises, e.g. (deliver an-external-promise (self)) or somesuch.

ulises commented 9 years ago

Oh, another thing, if I add :bootstrap true to project.clj, then I get the NPE error mentioned in #43

Output from running a test with :bootstrap true:

lein test :only sliver.node-test/spawn-test

ERROR in (spawn-test) (ActorLoader.java:368)
Uncaught exception, not in assertion.
expected: nil
  actual: java.lang.NullPointerException: null
 at co.paralleluniverse.actors.ActorLoader.loadCurrentClass (ActorLoader.java:368)
    co.paralleluniverse.actors.ActorLoader.getCurrentClassFor (ActorLoader.java:392)
    co.paralleluniverse.actors.ActorLoader.getReplacementFor0 (ActorLoader.java:379)
    co.paralleluniverse.actors.ActorLoader.getReplacementFor (ActorLoader.java:117)
    co.paralleluniverse.actors.Actor.checkReplacement (Actor.java:135)
    co.paralleluniverse.actors.Actor.spawn (Actor.java:235)
    co.paralleluniverse.actors.Actor.spawn (Actor.java:203)
    sliver.node.Node.spawn (node.clj:182)
    sliver.node_test/fn (node_test.clj:87)
    clojure.test$test_var$fn__7187.invoke (test.clj:704)
    clojure.test$test_var.invoke (test.clj:704)
    clojure.test$test_vars$fn__7209$fn__7214.invoke (test.clj:722)
    sliver.node_test$epmd_erl_fixture.invoke (node_test.clj:15)
    clojure.test$compose_fixtures$fn__7181$fn__7182.invoke (test.clj:681)
    clojure.test$default_fixture.invoke (test.clj:674)
    clojure.test$compose_fixtures$fn__7181.invoke (test.clj:681)
    clojure.test$test_vars$fn__7209.invoke (test.clj:722)
    clojure.test$default_fixture.invoke (test.clj:674)
    clojure.test$test_vars.invoke (test.clj:718)
    clojure.test$test_all_vars.invoke (test.clj:728)
    clojure.test$test_ns.invoke (test.clj:747)
    clojure.core$map$fn__4245.invoke (core.clj:2559)
    clojure.lang.LazySeq.sval (LazySeq.java:40)
    clojure.lang.LazySeq.seq (LazySeq.java:49)
    clojure.lang.Cons.next (Cons.java:39)
    clojure.lang.RT.boundedLength (RT.java:1654)
    clojure.lang.RestFn.applyTo (RestFn.java:130)
    clojure.core$apply.invoke (core.clj:626)
    clojure.test$run_tests.doInvoke (test.clj:762)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.core$apply.invoke (core.clj:624)
ulises commented 9 years ago

Aha! Silly me. I was calling (self) and not @self. This is a non-issue.