ets weirdness when using -run

Bengt Kleberg eleberg@REDACTED
Wed Jun 19 10:38:17 CEST 2002


> Date: Tue, 18 Jun 2002 16:24:13 -0500
> From: Chris Pressey <cpressey@REDACTED>
> Subject: ets weirdness when using -run
> To: erlang-questions@REDACTED
> MIME-version: 1.0
> Content-transfer-encoding: 7BIT
> 
> I have a program that uses a public, named ets table like so:
...deleted

> But here is what happens when I run it from the command line:
> 
> 
...deleted

> =ERROR REPORT==== 18-Jun-2002::16:22:00 ===
> Error in process <0.30.0> with exit value:
> {badarg,[{ets,lookup,[my_ets,"Key"]},{eg,new,1}]}
> 
> 
> Any thoughts on what I might be doing wrong to make my_ets just vanish
> like that?

at a guesss your original, ets table creating, process exists before
the spawned process gets to the ets:lookup() bit. no original process,
no ets table.

i have included a slight delay before exiting, and then your program
seems to work. see below.


bengt
-------------- next part --------------
-module(eg).
-export([get_args/0, new/1]).

get_args() ->
	start( "Key" ),
%	init:stop( ).
	timer:apply_after( 2000, init, stop, [] ).

start(Key) ->
  my_ets = ets:new(my_ets, [public, named_table]),
  io:fwrite("~p~n", [ets:info(my_ets)]),
  start_new(lists:flatten(Key)).

start_new(Key) ->
  spawn(?MODULE, new, [Key]).

new(Key) ->
  io:fwrite("~p~n", [ets:info(my_ets)]),
  case ets:lookup(my_ets, Key) of
    [_] ->
       io:fwrite("Already in database~n");
    _ ->
       io:fwrite("Not yet in database~n")
  end.


More information about the erlang-questions mailing list